mirror of
https://github.com/wassname/talk.git
synced 2026-09-11 12:51:33 +08:00
merge master
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import {gql} from 'react-apollo';
|
||||
|
||||
export const getTotalActionCount = (type, comment) => {
|
||||
return comment.action_summaries
|
||||
.filter(s => s.__typename === type)
|
||||
.filter((s) => s.__typename === type)
|
||||
.reduce((total, summary) => {
|
||||
return total + summary.count;
|
||||
}, 0);
|
||||
@@ -10,14 +12,14 @@ export const iPerformedThisAction = (type, comment) => {
|
||||
|
||||
// if there is a current_user on any of the ActionSummary(s), the user performed this action
|
||||
return comment.action_summaries
|
||||
.filter(a => a.__typename === type)
|
||||
.some(a => a.current_user);
|
||||
.filter((a) => a.__typename === type)
|
||||
.some((a) => a.current_user);
|
||||
};
|
||||
|
||||
export const getMyActionSummary = (type, comment) => {
|
||||
return comment.action_summaries
|
||||
.filter(a => a.__typename === type)
|
||||
.find(a => a.current_user);
|
||||
.filter((a) => a.__typename === type)
|
||||
.find((a) => a.current_user);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -27,7 +29,7 @@ export const getMyActionSummary = (type, comment) => {
|
||||
*/
|
||||
|
||||
export const getActionSummary = (type, comment) => {
|
||||
return comment.action_summaries.filter(a => a.__typename === type);
|
||||
return comment.action_summaries.filter((a) => a.__typename === type);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -61,3 +63,11 @@ export function separateDataAndRoot(
|
||||
root,
|
||||
};
|
||||
}
|
||||
|
||||
export function mergeDocuments(documents) {
|
||||
const main = typeof documents[0] === 'string' ? documents[0] : documents[0].loc.source.body;
|
||||
const substitutions = documents.slice(1);
|
||||
const literals = [main, ...substitutions.map(() => '\n')];
|
||||
return gql.apply(null, [literals, ...substitutions]);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ const mutationRoles = {
|
||||
const roles = {...basicRoles, ...queryRoles, ...mutationRoles};
|
||||
|
||||
export const can = (user, ...perms) => {
|
||||
return perms.every(perm => {
|
||||
return perms.every((perm) => {
|
||||
const role = roles[perm];
|
||||
if (typeof role === 'undefined') {
|
||||
throw new Error(`${perm} is not a valid role`);
|
||||
|
||||
Reference in New Issue
Block a user