Follow linter

This commit is contained in:
syuilo 2017-03-04 04:28:38 +09:00
parent 4e3d617797
commit 3c1b92baa1
70 changed files with 514 additions and 780 deletions

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -13,9 +11,7 @@ import Like from '../../../models/like';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id).expect.id().required().qed(); const [postId, postIdErr] = it(params.post_id).expect.id().required().qed();
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
@ -63,7 +59,7 @@ module.exports = (params) =>
)[0]; )[0];
if (data) { if (data) {
graph.push(data) graph.push(data);
} else { } else {
graph.push({ graph.push({
date: { date: {
@ -72,8 +68,8 @@ module.exports = (params) =>
day: day.getDate() day: day.getDate()
}, },
count: 0 count: 0
}) });
}; }
} }
res(graph); res(graph);

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -13,9 +11,7 @@ import Like from '../../../models/like';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id).expect.id().required().qed(); const [postId, postIdErr] = it(params.post_id).expect.id().required().qed();
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -12,9 +10,7 @@ import Post from '../../../models/post';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id).expect.id().required().qed(); const [postId, postIdErr] = it(params.post_id).expect.id().required().qed();
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
@ -62,7 +58,7 @@ module.exports = (params) =>
)[0]; )[0];
if (data) { if (data) {
graph.push(data) graph.push(data);
} else { } else {
graph.push({ graph.push({
date: { date: {
@ -71,8 +67,8 @@ module.exports = (params) =>
day: day.getDate() day: day.getDate()
}, },
count: 0 count: 0
}) });
}; }
} }
res(graph); res(graph);

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -12,9 +10,7 @@ import Post from '../../../models/post';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id).expect.id().required().qed(); const [postId, postIdErr] = it(params.post_id).expect.id().required().qed();
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
@ -62,7 +58,7 @@ module.exports = (params) =>
)[0]; )[0];
if (data) { if (data) {
graph.push(data) graph.push(data);
} else { } else {
graph.push({ graph.push({
date: { date: {
@ -71,8 +67,8 @@ module.exports = (params) =>
day: day.getDate() day: day.getDate()
}, },
count: 0 count: 0
}) });
}; }
} }
res(graph); res(graph);

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -13,9 +11,7 @@ import Following from '../../../models/following';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id).expect.id().required().qed(); const [userId, userIdErr] = it(params.user_id).expect.id().required().qed();
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -13,9 +11,7 @@ import Following from '../../../models/following';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id).expect.id().required().qed(); const [userId, userIdErr] = it(params.user_id).expect.id().required().qed();
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -13,9 +11,7 @@ import Like from '../../../models/like';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id).expect.id().required().qed(); const [userId, userIdErr] = it(params.user_id).expect.id().required().qed();
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
@ -67,7 +63,7 @@ module.exports = (params) =>
)[0]; )[0];
if (data) { if (data) {
graph.push(data) graph.push(data);
} else { } else {
graph.push({ graph.push({
date: { date: {
@ -76,8 +72,8 @@ module.exports = (params) =>
day: day.getDate() day: day.getDate()
}, },
count: 0 count: 0
}) });
}; }
} }
res(graph); res(graph);

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -13,9 +11,7 @@ import Post from '../../../models/post';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id).expect.id().required().qed(); const [userId, userIdErr] = it(params.user_id).expect.id().required().qed();
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
@ -95,7 +91,7 @@ module.exports = (params) =>
)[0]; )[0];
if (data) { if (data) {
graph.push(data) graph.push(data);
} else { } else {
graph.push({ graph.push({
date: { date: {
@ -106,8 +102,8 @@ module.exports = (params) =>
posts: 0, posts: 0,
reposts: 0, reposts: 0,
replies: 0 replies: 0
}) });
}; }
} }
res(graph); res(graph);

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -69,9 +67,7 @@ import serialize from '../../serializers/app';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = async (params, user) => module.exports = async (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'name_id' parameter // Get 'name_id' parameter
const [nameId, nameIdErr] = it(params.name_id).expect.string().required().validate(isValidNameId).qed(); const [nameId, nameIdErr] = it(params.name_id).expect.string().required().validate(isValidNameId).qed();
if (nameIdErr) return rej('invalid name_id param'); if (nameIdErr) return rej('invalid name_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -42,9 +40,7 @@ import { isValidNameId } from '../../../models/app';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = async (params) => module.exports = async (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'name_id' parameter // Get 'name_id' parameter
const [nameId, nameIdErr] = it(params.name_id).expect.string().required().validate(isValidNameId).qed(); const [nameId, nameIdErr] = it(params.name_id).expect.string().required().validate(isValidNameId).qed();
if (nameIdErr) return rej('invalid name_id param'); if (nameIdErr) return rej('invalid name_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -46,9 +44,7 @@ import serialize from '../../serializers/app';
* @param {any} isSecure * @param {any} isSecure
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user, _, isSecure) => module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'app_id' parameter // Get 'app_id' parameter
const [appId, appIdErr] = it(params.app_id, 'id'); const [appId, appIdErr] = it(params.app_id, 'id');
if (appIdErr) return rej('invalid app_id param'); if (appIdErr) return rej('invalid app_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -40,9 +38,7 @@ import AccessToken from '../../models/access-token';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'token' parameter // Get 'token' parameter
const [token, tokenErr] = it(params.token).expect.string().required().qed(); const [token, tokenErr] = it(params.token).expect.string().required().qed();
if (tokenErr) return rej('invalid token param'); if (tokenErr) return rej('invalid token param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -46,9 +44,7 @@ import config from '../../../../conf';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'app_secret' parameter // Get 'app_secret' parameter
const [appSecret, appSecretErr] = it(params.app_secret).expect.string().required().qed(); const [appSecret, appSecretErr] = it(params.app_secret).expect.string().required().qed();
if (appSecretErr) return rej('invalid app_secret param'); if (appSecretErr) return rej('invalid app_secret param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -54,9 +52,7 @@ import serialize from '../../../serializers/auth-session';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'token' parameter // Get 'token' parameter
const [token, tokenErr] = it(params.token).expect.string().required().qed(); const [token, tokenErr] = it(params.token).expect.string().required().qed();
if (tokenErr) return rej('invalid token param'); if (tokenErr) return rej('invalid token param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -51,62 +49,61 @@ import serialize from '../../../serializers/user';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { // Get 'app_secret' parameter
// Get 'app_secret' parameter const [appSecret, appSecretErr] = it(params.app_secret).expect.string().required().qed();
const [appSecret, appSecretErr] = it(params.app_secret).expect.string().required().qed(); if (appSecretErr) return rej('invalid app_secret param');
if (appSecretErr) return rej('invalid app_secret param');
// Lookup app // Lookup app
const app = await App.findOne({ const app = await App.findOne({
secret: appSecret secret: appSecret
});
if (app == null) {
return rej('app not found');
}
// Get 'token' parameter
const [token, tokenErr] = it(params.token).expect.string().required().qed();
if (tokenErr) return rej('invalid token param');
// Fetch token
const session = await AuthSess
.findOne({
token: token,
app_id: app._id
});
if (session === null) {
return rej('session not found');
}
if (session.user_id == null) {
return rej('this session is not allowed yet');
}
// Lookup access token
const accessToken = await AccessToken.findOne({
app_id: app._id,
user_id: session.user_id
});
// Delete session
/* https://github.com/Automattic/monk/issues/178
AuthSess.deleteOne({
_id: session._id
});
*/
AuthSess.remove({
_id: session._id
});
// Response
res({
access_token: accessToken.token,
user: await serialize(session.user_id, null, {
detail: true
})
});
}); });
if (app == null) {
return rej('app not found');
}
// Get 'token' parameter
const [token, tokenErr] = it(params.token).expect.string().required().qed();
if (tokenErr) return rej('invalid token param');
// Fetch token
const session = await AuthSess
.findOne({
token: token,
app_id: app._id
});
if (session === null) {
return rej('session not found');
}
if (session.user_id == null) {
return rej('this session is not allowed yet');
}
// Lookup access token
const accessToken = await AccessToken.findOne({
app_id: app._id,
user_id: session.user_id
});
// Delete session
/* https://github.com/Automattic/monk/issues/178
AuthSess.deleteOne({
_id: session._id
});
*/
AuthSess.remove({
_id: session._id
});
// Response
res({
access_token: accessToken.token,
user: await serialize(session.user_id, null, {
detail: true
})
});
});

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -12,29 +10,28 @@ import DriveFile from '../models/drive-file';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { // Calculate drive usage
// Calculate drive usage const usage = ((await DriveFile
const usage = ((await DriveFile .aggregate([
.aggregate([ { $match: { user_id: user._id } },
{ $match: { user_id: user._id } }, {
{ $project: {
$project: { datasize: true
datasize: true
}
},
{
$group: {
_id: null,
usage: { $sum: '$datasize' }
}
} }
]))[0] || { },
usage: 0 {
}).usage; $group: {
_id: null,
usage: { $sum: '$datasize' }
}
}
]))[0] || {
usage: 0
}).usage;
res({ res({
capacity: user.drive_capacity, capacity: user.drive_capacity,
usage: usage usage: usage
});
}); });
});

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -15,9 +13,7 @@ import serialize from '../../serializers/drive-file';
* @param {any} app * @param {any} app
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app) => module.exports = (params, user, app) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -17,15 +15,13 @@ import create from '../../../common/add-file-to-drive';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (file, params, user) => module.exports = (file, params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
if (file == null) { if (file == null) {
return rej('file is required'); return rej('file is required');
} }
const buffer = fs.readFileSync(file.path); const buffer = fs.readFileSync(file.path);
fs.unlink(file.path, (err) => { if (err) console.log(err) }); fs.unlink(file.path, (err) => { if (err) console.log(err); });
// Get 'name' parameter // Get 'name' parameter
let name = file.originalname; let name = file.originalname;

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../../serializers/drive-file';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'name' parameter // Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().required().qed(); const [name, nameErr] = it(params.name).expect.string().required().qed();
if (nameErr) return rej('invalid name param'); if (nameErr) return rej('invalid name param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../../serializers/drive-file';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'file_id' parameter // Get 'file_id' parameter
const [fileId, fileIdErr] = it(params.file_id).expect.id().required().qed(); const [fileId, fileIdErr] = it(params.file_id).expect.id().required().qed();
if (fileIdErr) return rej('invalid file_id param'); if (fileIdErr) return rej('invalid file_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -17,9 +15,7 @@ import event from '../../../event';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'file_id' parameter // Get 'file_id' parameter
const [fileId, fileIdErr] = it(params.file_id).expect.id().required().qed(); const [fileId, fileIdErr] = it(params.file_id).expect.id().required().qed();
if (fileIdErr) return rej('invalid file_id param'); if (fileIdErr) return rej('invalid file_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -17,9 +15,7 @@ import create from '../../../common/add-file-to-drive';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'url' parameter // Get 'url' parameter
// TODO: Validate this url // TODO: Validate this url
const [url, urlErr] = it(params.url).expect.string().required().qed(); const [url, urlErr] = it(params.url).expect.string().required().qed();

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -15,9 +13,7 @@ import serialize from '../../serializers/drive-folder';
* @param {any} app * @param {any} app
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app) => module.exports = (params, user, app) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -16,9 +14,7 @@ import event from '../../../event';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'name' parameter // Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().validate(isValidFolderName).default('無題のフォルダー').qed(); const [name, nameErr] = it(params.name).expect.string().validate(isValidFolderName).default('無題のフォルダー').qed();
if (nameErr) return rej('invalid name param'); if (nameErr) return rej('invalid name param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../../serializers/drive-folder';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'name' parameter // Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().required().qed(); const [name, nameErr] = it(params.name).expect.string().required().qed();
if (nameErr) return rej('invalid name param'); if (nameErr) return rej('invalid name param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../../serializers/drive-folder';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'folder_id' parameter // Get 'folder_id' parameter
const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().qed(); const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().qed();
if (folderIdErr) return rej('invalid folder_id param'); if (folderIdErr) return rej('invalid folder_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -16,9 +14,7 @@ import event from '../../../event';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'folder_id' parameter // Get 'folder_id' parameter
const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().qed(); const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().qed();
if (folderIdErr) return rej('invalid folder_id param'); if (folderIdErr) return rej('invalid folder_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/drive-file';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -17,9 +15,7 @@ import serializeUser from '../../serializers/user';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
const follower = user; const follower = user;
// Get 'user_id' parameter // Get 'user_id' parameter

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -16,9 +14,7 @@ import serializeUser from '../../serializers/user';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
const follower = user; const follower = user;
// Get 'user_id' parameter // Get 'user_id' parameter

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../serializers/user';
* @param {Boolean} isSecure * @param {Boolean} isSecure
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user, _, isSecure) => module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Serialize // Serialize
res(await serialize(user, user, { res(await serialize(user, user, {
detail: true, detail: true,

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import Appdata from '../../../models/appdata';
* @param {Boolean} isSecure * @param {Boolean} isSecure
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app, isSecure) => module.exports = (params, user, app, isSecure) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'key' parameter // Get 'key' parameter
let key = params.key; let key = params.key;
if (key === undefined) { if (key === undefined) {

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -17,9 +15,7 @@ import event from '../../../event';
* @param {Boolean} isSecure * @param {Boolean} isSecure
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app, isSecure) => module.exports = (params, user, app, isSecure) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
const data = params.data; const data = params.data;
if (data == null) { if (data == null) {
return rej('data is required'); return rej('data is required');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/app';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/post';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -15,9 +13,7 @@ import getFriends from '../../common/get-friends';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'following' parameter // Get 'following' parameter
const [following, followingError] = const [following, followingError] =
it(params.following).expect.boolean().default(false).qed(); it(params.following).expect.boolean().default(false).qed();

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/signin';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -19,9 +17,7 @@ import config from '../../../conf';
* @param {boolean} isSecure * @param {boolean} isSecure
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = async (params, user, _, isSecure) => module.exports = async (params, user, _, isSecure) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'name' parameter // Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().validate(isValidName).qed(); const [name, nameErr] = it(params.name).expect.string().validate(isValidName).qed();
if (nameErr) return rej('invalid name param'); if (nameErr) return rej('invalid name param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/messaging-message';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -17,9 +15,7 @@ import { publishMessagingStream } from '../../event';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'user_id' parameter // Get 'user_id' parameter
const [recipientId, recipientIdErr] = it(params.user_id).expect.id().required().qed(); const [recipientId, recipientIdErr] = it(params.user_id).expect.id().required().qed();
if (recipientIdErr) return rej('invalid user_id param'); if (recipientIdErr) return rej('invalid user_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -21,9 +19,7 @@ import config from '../../../../conf';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'user_id' parameter // Get 'user_id' parameter
const [recipientId, recipientIdErr] = it(params.user_id).expect.id().required().qed(); const [recipientId, recipientIdErr] = it(params.user_id).expect.id().required().qed();
if (recipientIdErr) return rej('invalid user_id param'); if (recipientIdErr) return rej('invalid user_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -12,9 +10,7 @@ import Message from '../../models/messaging-message';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
const count = await Message const count = await Message
.count({ .count({
recipient_id: user._id, recipient_id: user._id,

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -40,13 +38,12 @@ import config from '../../conf';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { const commit = await prominence(git).getLastCommit();
const commit = await prominence(git).getLastCommit();
res({ res({
maintainer: config.maintainer, maintainer: config.maintainer,
commit: commit.shortHash, commit: commit.shortHash,
secure: config.https.enable secure: config.https.enable
});
}); });
});

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/app';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -15,36 +13,35 @@ import event from '../../event';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { const [notificationId, notificationIdErr] = it(params.notification_id).expect.id().required().qed();
const [notificationId, notificationIdErr] = it(params.notification_id).expect.id().required().qed(); if (notificationIdErr) return rej('invalid notification_id param');
if (notificationIdErr) return rej('invalid notification_id param');
// Get notification // Get notification
const notification = await Notification const notification = await Notification
.findOne({ .findOne({
_id: notificationId, _id: notificationId,
i: user._id i: user._id
});
if (notification === null) {
return rej('notification-not-found');
}
// Update
notification.is_read = true;
Notification.update({ _id: notification._id }, {
$set: {
is_read: true
}
}); });
// Response if (notification === null) {
res(); return rej('notification-not-found');
}
// Serialize // Update
const notificationObj = await serialize(notification); notification.is_read = true;
Notification.update({ _id: notification._id }, {
// Publish read_notification event $set: {
event(user._id, 'read_notification', notificationObj); is_read: true
}
}); });
// Response
res();
// Serialize
const notificationObj = await serialize(notification);
// Publish read_notification event
event(user._id, 'read_notification', notificationObj);
});

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -13,64 +11,63 @@ import serialize from '../serializers/post';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { // Get 'include_replies' parameter
// Get 'include_replies' parameter const [includeReplies, includeRepliesErr] = it(params.include_replies).expect.boolean().default(true).qed();
const [includeReplies, includeRepliesErr] = it(params.include_replies).expect.boolean().default(true).qed(); if (includeRepliesErr) return rej('invalid include_replies param');
if (includeRepliesErr) return rej('invalid include_replies param');
// Get 'include_reposts' parameter // Get 'include_reposts' parameter
const [includeReposts, includeRepostsErr] = it(params.include_reposts).expect.boolean().default(true).qed(); const [includeReposts, includeRepostsErr] = it(params.include_reposts).expect.boolean().default(true).qed();
if (includeRepostsErr) return rej('invalid include_reposts param'); if (includeRepostsErr) return rej('invalid include_reposts param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed(); const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed(); const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified
if (sinceId && maxId) { if (sinceId && maxId) {
return rej('cannot set since_id and max_id'); return rej('cannot set since_id and max_id');
} }
// Construct query // Construct query
const sort = { const sort = {
_id: -1 _id: -1
};
const query = {} as any;
if (sinceId) {
sort._id = 1;
query._id = {
$gt: sinceId
}; };
const query = {} as any; } else if (maxId) {
if (sinceId) { query._id = {
sort._id = 1; $lt: maxId
query._id = { };
$gt: sinceId }
};
} else if (maxId) {
query._id = {
$lt: maxId
};
}
if (!includeReplies) { if (!includeReplies) {
query.reply_to_id = null; query.reply_to_id = null;
} }
if (!includeReposts) { if (!includeReposts) {
query.repost_id = null; query.repost_id = null;
} }
// Issue query // Issue query
const posts = await Post const posts = await Post
.find(query, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}); });
// Serialize // Serialize
res(await Promise.all(posts.map(async post => await serialize(post)))); res(await Promise.all(posts.map(async post => await serialize(post))));
}); });

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/post';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id', true); const [postId, postIdErr] = it(params.post_id, 'id', true);
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -23,9 +21,7 @@ import config from '../../../conf';
* @param {any} app * @param {any} app
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app) => module.exports = (params, user, app) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'text' parameter // Get 'text' parameter
const [text, textErr] = it(params.text).must.be.a.string().validate(isValidText).qed(); const [text, textErr] = it(params.text).must.be.a.string().validate(isValidText).qed();
if (textErr) return rej('invalid text'); if (textErr) return rej('invalid text');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,38 +12,37 @@ import Post from '../../../models/post';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { // Get 'post_id' parameter
// Get 'post_id' parameter const [postId, postIdErr] = it(params.post_id, 'id', true);
const [postId, postIdErr] = it(params.post_id, 'id', true); if (postIdErr) return rej('invalid post_id param');
if (postIdErr) return rej('invalid post_id param');
// Get favoritee // Get favoritee
const post = await Post.findOne({ const post = await Post.findOne({
_id: postId _id: postId
});
if (post === null) {
return rej('post not found');
}
// if already favorited
const exist = await Favorite.findOne({
post_id: post._id,
user_id: user._id
});
if (exist !== null) {
return rej('already favorited');
}
// Create favorite
await Favorite.insert({
created_at: new Date(),
post_id: post._id,
user_id: user._id
});
// Send response
res();
}); });
if (post === null) {
return rej('post not found');
}
// if already favorited
const exist = await Favorite.findOne({
post_id: post._id,
user_id: user._id
});
if (exist !== null) {
return rej('already favorited');
}
// Create favorite
await Favorite.insert({
created_at: new Date(),
post_id: post._id,
user_id: user._id
});
// Send response
res();
});

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,36 +12,35 @@ import Post from '../../../models/post';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { // Get 'post_id' parameter
// Get 'post_id' parameter const [postId, postIdErr] = it(params.post_id, 'id', true);
const [postId, postIdErr] = it(params.post_id, 'id', true); if (postIdErr) return rej('invalid post_id param');
if (postIdErr) return rej('invalid post_id param');
// Get favoritee // Get favoritee
const post = await Post.findOne({ const post = await Post.findOne({
_id: postId _id: postId
});
if (post === null) {
return rej('post not found');
}
// if already favorited
const exist = await Favorite.findOne({
post_id: post._id,
user_id: user._id
});
if (exist === null) {
return rej('already not favorited');
}
// Delete favorite
await Favorite.deleteOne({
_id: exist._id
});
// Send response
res();
}); });
if (post === null) {
return rej('post not found');
}
// if already favorited
const exist = await Favorite.findOne({
post_id: post._id,
user_id: user._id
});
if (exist === null) {
return rej('already not favorited');
}
// Delete favorite
await Favorite.deleteOne({
_id: exist._id
});
// Send response
res();
});

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -15,9 +13,7 @@ import serialize from '../../serializers/user';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id', true); const [postId, postIdErr] = it(params.post_id, 'id', true);
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -16,70 +14,69 @@ import notify from '../../../common/notify';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { // Get 'post_id' parameter
// Get 'post_id' parameter const [postId, postIdErr] = it(params.post_id, 'id', true);
const [postId, postIdErr] = it(params.post_id, 'id', true); if (postIdErr) return rej('invalid post_id param');
if (postIdErr) return rej('invalid post_id param');
// Get likee // Get likee
const post = await Post.findOne({ const post = await Post.findOne({
_id: postId _id: postId
});
if (post === null) {
return rej('post not found');
}
// Myself
if (post.user_id.equals(user._id)) {
return rej('-need-translate-');
}
// if already liked
const exist = await Like.findOne({
post_id: post._id,
user_id: user._id,
deleted_at: { $exists: false }
});
if (exist !== null) {
return rej('already liked');
}
// Create like
await Like.insert({
created_at: new Date(),
post_id: post._id,
user_id: user._id
});
// Send response
res();
// Increment likes count
Post.update({ _id: post._id }, {
$inc: {
likes_count: 1
}
});
// Increment user likes count
User.update({ _id: user._id }, {
$inc: {
likes_count: 1
}
});
// Increment user liked count
User.update({ _id: post.user_id }, {
$inc: {
liked_count: 1
}
});
// Notify
notify(post.user_id, user._id, 'like', {
post_id: post._id
});
}); });
if (post === null) {
return rej('post not found');
}
// Myself
if (post.user_id.equals(user._id)) {
return rej('-need-translate-');
}
// if already liked
const exist = await Like.findOne({
post_id: post._id,
user_id: user._id,
deleted_at: { $exists: false }
});
if (exist !== null) {
return rej('already liked');
}
// Create like
await Like.insert({
created_at: new Date(),
post_id: post._id,
user_id: user._id
});
// Send response
res();
// Increment likes count
Post.update({ _id: post._id }, {
$inc: {
likes_count: 1
}
});
// Increment user likes count
User.update({ _id: user._id }, {
$inc: {
likes_count: 1
}
});
// Increment user liked count
User.update({ _id: post.user_id }, {
$inc: {
liked_count: 1
}
});
// Notify
notify(post.user_id, user._id, 'like', {
post_id: post._id
});
});

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -16,62 +14,61 @@ import User from '../../../models/user';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { // Get 'post_id' parameter
// Get 'post_id' parameter const [postId, postIdErr] = it(params.post_id, 'id', true);
const [postId, postIdErr] = it(params.post_id, 'id', true); if (postIdErr) return rej('invalid post_id param');
if (postIdErr) return rej('invalid post_id param');
// Get likee // Get likee
const post = await Post.findOne({ const post = await Post.findOne({
_id: postId _id: postId
});
if (post === null) {
return rej('post not found');
}
// if already liked
const exist = await Like.findOne({
post_id: post._id,
user_id: user._id,
deleted_at: { $exists: false }
});
if (exist === null) {
return rej('already not liked');
}
// Delete like
await Like.update({
_id: exist._id
}, {
$set: {
deleted_at: new Date()
}
});
// Send response
res();
// Decrement likes count
Post.update({ _id: post._id }, {
$inc: {
likes_count: -1
}
});
// Decrement user likes count
User.update({ _id: user._id }, {
$inc: {
likes_count: -1
}
});
// Decrement user liked count
User.update({ _id: post.user_id }, {
$inc: {
liked_count: -1
}
});
}); });
if (post === null) {
return rej('post not found');
}
// if already liked
const exist = await Like.findOne({
post_id: post._id,
user_id: user._id,
deleted_at: { $exists: false }
});
if (exist === null) {
return rej('already not liked');
}
// Delete like
await Like.update({
_id: exist._id
}, {
$set: {
deleted_at: new Date()
}
});
// Send response
res();
// Decrement likes count
Post.update({ _id: post._id }, {
$inc: {
likes_count: -1
}
});
// Decrement user likes count
User.update({ _id: user._id }, {
$inc: {
likes_count: -1
}
});
// Decrement user liked count
User.update({ _id: post.user_id }, {
$inc: {
liked_count: -1
}
});
});

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -15,9 +13,7 @@ import serialize from '../../serializers/post';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'following' parameter // Get 'following' parameter
const [following, followingError] = const [following, followingError] =
it(params.following).expect.boolean().default(false).qed(); it(params.following).expect.boolean().default(false).qed();

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -15,69 +13,68 @@ import notify from '../../../common/notify';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { // Get 'post_id' parameter
// Get 'post_id' parameter const [postId, postIdErr] = it(params.post_id, 'id', true);
const [postId, postIdErr] = it(params.post_id, 'id', true); if (postIdErr) return rej('invalid post_id param');
if (postIdErr) return rej('invalid post_id param');
// Get votee // Get votee
const post = await Post.findOne({ const post = await Post.findOne({
_id: postId _id: postId
});
if (post === null) {
return rej('post not found');
}
if (post.poll == null) {
return rej('poll not found');
}
// Get 'choice' parameter
const [choice, choiceError] =
it(params.choice).expect.string()
.required()
.validate(c => post.poll.choices.some(x => x.id == c))
.qed();
if (choiceError) return rej('invalid choice param');
// if already voted
const exist = await Vote.findOne({
post_id: post._id,
user_id: user._id
});
if (exist !== null) {
return rej('already voted');
}
// Create vote
await Vote.insert({
created_at: new Date(),
post_id: post._id,
user_id: user._id,
choice: choice
});
// Send response
res();
const inc = {};
inc[`poll.choices.${findWithAttr(post.poll.choices, 'id', choice)}.votes`] = 1;
// Increment likes count
Post.update({ _id: post._id }, {
$inc: inc
});
// Notify
notify(post.user_id, user._id, 'poll_vote', {
post_id: post._id,
choice: choice
});
}); });
if (post === null) {
return rej('post not found');
}
if (post.poll == null) {
return rej('poll not found');
}
// Get 'choice' parameter
const [choice, choiceError] =
it(params.choice).expect.string()
.required()
.validate(c => post.poll.choices.some(x => x.id == c))
.qed();
if (choiceError) return rej('invalid choice param');
// if already voted
const exist = await Vote.findOne({
post_id: post._id,
user_id: user._id
});
if (exist !== null) {
return rej('already voted');
}
// Create vote
await Vote.insert({
created_at: new Date(),
post_id: post._id,
user_id: user._id,
choice: choice
});
// Send response
res();
const inc = {};
inc[`poll.choices.${findWithAttr(post.poll.choices, 'id', choice)}.votes`] = 1;
// Increment likes count
Post.update({ _id: post._id }, {
$inc: inc
});
// Notify
notify(post.user_id, user._id, 'poll_vote', {
post_id: post._id,
choice: choice
});
});
function findWithAttr(array, attr, value) { function findWithAttr(array, attr, value) {
for (let i = 0; i < array.length; i += 1) { for (let i = 0; i < array.length; i += 1) {
if (array[i][attr] === value) { if (array[i][attr] === value) {

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/post';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id', true); const [postId, postIdErr] = it(params.post_id, 'id', true);
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/post';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id', true); const [postId, postIdErr] = it(params.post_id, 'id', true);
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -17,9 +15,7 @@ import config from '../../../conf';
* @param {any} me * @param {any} me
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'query' parameter // Get 'query' parameter
const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').qed(); const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').qed();
if (queryError) return rej('invalid query param'); if (queryError) return rej('invalid query param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/post';
* @param {any} user * @param {any} user
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id', true); const [postId, postIdErr] = it(params.post_id, 'id', true);
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -16,9 +14,7 @@ import serialize from '../../serializers/post';
* @param {any} app * @param {any} app
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app) => module.exports = (params, user, app) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -13,9 +11,7 @@ import { validateUsername } from '../../models/user';
* @param {any} params * @param {any} params
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = async (params) => module.exports = async (params) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'username' parameter // Get 'username' parameter
const [username, usernameError] = it(params.username).expect.string().required().trim().validate(validateUsername).qed(); const [username, usernameError] = it(params.username).expect.string().required().trim().validate(validateUsername).qed();
if (usernameError) return rej('invalid username param'); if (usernameError) return rej('invalid username param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,49 +12,48 @@ import serialize from '../serializers/user';
* @param {any} me * @param {any} me
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) => new Promise(async (res, rej) => {
new Promise(async (res, rej) => { // Get 'limit' parameter
// Get 'limit' parameter const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); if (limitErr) return rej('invalid limit param');
if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed(); const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed(); const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified
if (sinceId && maxId) { if (sinceId && maxId) {
return rej('cannot set since_id and max_id'); return rej('cannot set since_id and max_id');
} }
// Construct query // Construct query
const sort = { const sort = {
_id: -1 _id: -1
};
const query = {} as any;
if (sinceId) {
sort._id = 1;
query._id = {
$gt: sinceId
}; };
const query = {} as any; } else if (maxId) {
if (sinceId) { query._id = {
sort._id = 1; $lt: maxId
query._id = { };
$gt: sinceId }
};
} else if (maxId) {
query._id = {
$lt: maxId
};
}
// Issue query // Issue query
const users = await User const users = await User
.find(query, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}); });
// Serialize // Serialize
res(await Promise.all(users.map(async user => res(await Promise.all(users.map(async user =>
await serialize(user, me)))); await serialize(user, me))));
}); });

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -16,9 +14,7 @@ import getFriends from '../../common/get-friends';
* @param {any} me * @param {any} me
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id, 'id', true); const [userId, userIdErr] = it(params.user_id, 'id', true);
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -16,9 +14,7 @@ import getFriends from '../../common/get-friends';
* @param {any} me * @param {any} me
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id, 'id', true); const [userId, userIdErr] = it(params.user_id, 'id', true);
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -15,9 +13,7 @@ import serialize from '../../serializers/post';
* @param {any} me * @param {any} me
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id, 'id'); const [userId, userIdErr] = it(params.user_id, 'id');
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -15,9 +13,7 @@ import getFriends from '../../common/get-friends';
* @param {any} me * @param {any} me
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'limit' parameter // Get 'limit' parameter
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed(); const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -17,9 +15,7 @@ const escapeRegexp = require('escape-regexp');
* @param {any} me * @param {any} me
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'query' parameter // Get 'query' parameter
const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').qed(); const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').qed();
if (queryError) return rej('invalid query param'); if (queryError) return rej('invalid query param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -15,9 +13,7 @@ import serialize from '../../serializers/user';
* @param {any} me * @param {any} me
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'query' parameter // Get 'query' parameter
const [query, queryError] = it(params.query).expect.string().required().trim().validate(validateUsername).qed(); const [query, queryError] = it(params.query).expect.string().required().trim().validate(validateUsername).qed();
if (queryError) return rej('invalid query param'); if (queryError) return rej('invalid query param');

View File

@ -1,5 +1,3 @@
'use strict';
/** /**
* Module dependencies * Module dependencies
*/ */
@ -14,9 +12,7 @@ import serialize from '../../serializers/user';
* @param {any} me * @param {any} me
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) => new Promise(async (res, rej) => {
new Promise(async (res, rej) =>
{
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id, 'id'); const [userId, userIdErr] = it(params.user_id, 'id');
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');

View File

@ -5,4 +5,3 @@ export default db.get('messaging_messages') as any; // fuck type definition
export function isValidText(text: string): boolean { export function isValidText(text: string): boolean {
return text.length <= 1000 && text.trim() != ''; return text.length <= 1000 && text.trim() != '';
} }