Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var meta = require('./meta');
var util = libRequire('db-client/util');
var funcs = {};
var moment = require('moment-timezone');
// funcs.exploreSearch = require('./exploreSearch');
funcs.patch = require('./patch');
funcs.search = function (spec) {
// TODO: should really be supporting the txid param
// query function wants an args list so we use apply since we
// are dynamically creating values out of what is specified
// console.log(require('util').inspect(this));
// console.log(JSON.stringify(spec));
return this.documents.query.apply(
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Promise = require('bluebird');
var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var _ = require('lodash');
var uuid = require('node-uuid');
var db;
var questionsDir = '/questions/';
var contributorPrefix = 'com.marklogic.samplestack.domain.Contributor';
var contributorDir = contributorPrefix + '/';
// TODO: pull contributor info from session
var contributorId = 'cf99542d-f024-4478-a6dc-7e723a51b040';
var contributorDisplayName = 'JoeUser';
var contributorUserName = 'joe@example.com';
var commentTemplate = {
'owner': {
'id': contributorId,
var Promise = require('bluebird');
var errs = libRequire('errors');
var qb = require('marklogic').queryBuilder;
module.exports = {
// POJO-managed docs "bury" the content under a Java fully qualified
// class name, so we find the first key an use it to locate the actual
// content
unwrapPojo: function (pojo) {
return pojo[Object.keys(pojo)[0]];
},
getOnlyContent: function (response) {
if (response.length !== 1) {
throw errs.cardinality({ length: response.length,
response: response });
}
else {
return response[0].content;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var meta = require('./meta');
var util = libRequire('db-client/util');
var funcs = {};
/**
* Handle an update to a contributor's reputation by patch the document.
*
* @param {String} txid The transaction ID.
* @param {String} id The contributor ID.
* @param {Number} repChange Increment or decrement value.
* @return {Promise} A promise object.
*/
funcs.patchReputation = function (txid, id, repChange) {
// add (or subtract) from reputation property
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;
module.exports = function (userSpec) {
var self = this;
return new Promise(function (resolve, reject) {
// TODO: should thie really be approx. 2-times slower? are we missing
// an index?
// self.documents.query(
// qb.where(
// qb.directory('com.marklogic.samplestack.domain.Contributor/'),
// qb.value('id', userId)
// )
// ).result(
//
var fetch;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;
var _ = require('lodash');
var uuid = require('node-uuid');
var generateUUID = function () {
return uuid.v4();
};
var questionTemplate = {
'accepted':false,
'acceptedAnswerId':null,
'answerCount':0,
'answers':[],
'comments':[],
'creationDate':new Date(),
'id':'',
'itemTally':0,
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;
module.exports = function (userSpec) {
var self = this;
return new Promise(function (resolve, reject) {
var fetch = self.documents.read(
'/questions/' + userSpec.questionId + '.json'
);
fetch.result(
function (response) {
if (response.length !== 1) {
return reject({
error: 'cardinalityViolation',
userSpec: userSpec,
count: response.length
});
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var meta = require('./meta');
var util = libRequire('db-client/util');
var errs = libRequire('errors');
var moment = require('moment-timezone');
var Promise = require('bluebird');
var qnaDoc = require('./index');
module.exports = function (txid, spec) {
var self = this;
/**
* Handles an upvote or downvote for a Samplestack question or answer.
* Performs three patch operations:
* 1. Adds the contributor ID to the array of upvoters or
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;
module.exports = function (userSpec) {
var self = this;
return new Promise(function (resolve, reject) {
var questionsDir = '/questions/';
var length = 10;
var start = (userSpec.start) ? parseInt(userSpec.start) : 1;
var searchText = (userSpec.q) ? userSpec.q : '';
var fetch = self.documents.query(
qb.where(
qb.directory(questionsDir),
qb.parsedFrom(searchText)
).slice(start,length).withOptions({categories: 'none'})
);
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;
module.exports = function (userSpec) {
var self = this;
return new Promise(function (resolve, reject) {
var contributorsDir = 'com.marklogic.samplestack.domain.Contributor/';
var length = 10;
var start = (userSpec.start) ? userSpec.start : 1;
var searchText = (userSpec.q) ? userSpec.q : '';
var fetch = self.documents.query(
qb.where(
qb.directory(contributorsDir),
qb.parsedFrom(searchText)
).slice(start,length).withOptions({categories: 'none'})
);