adding participatingAsId and canParticipateAsId fields
This commit is contained in:
1 parent
1158e418b1
commit
dd3c259887
1 file changed
+89
@@ -5,6 +5,9 @@ import {
|
||||
GraphQLList,
|
||||
GraphQLID,
|
||||
} from 'graphql';
|
||||
import axios from 'axios';
|
||||
import { ServiceUnavailableError } from '../../errors';
|
||||
import { Event } from '../../models';
|
||||
import {
|
||||
FormulaType,
|
||||
PlotterType,
|
||||
@@ -46,6 +49,92 @@ const EventType = new GraphQLObjectType({
|
||||
return parent.participants;
|
||||
},
|
||||
},
|
||||
participatingAsId: {
|
||||
type: new GraphQLList(GraphQLString),
|
||||
resolve({ id: _id }, arg, { authorization }) {
|
||||
if (!authorization) {
|
||||
return ({});
|
||||
}
|
||||
return new Promise((res, rej) => {
|
||||
axios({
|
||||
url: process.env.GATEWAY_ENDPOINT,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
{
|
||||
teams_TeamsByRole{
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
headers: { authorization },
|
||||
}).then(
|
||||
(result) => {
|
||||
const ret = [];
|
||||
Event.findOne({ _id }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
result.data.data.teams_TeamsByRole.forEach((team) => {
|
||||
if (event.participants.some(participant => participant.participantId === team.id)) {
|
||||
ret.push(team.id);
|
||||
}
|
||||
});
|
||||
res(ret);
|
||||
});
|
||||
},
|
||||
(error) => {
|
||||
rej(new ServiceUnavailableError(error));
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
canParticipateAsId: {
|
||||
type: new GraphQLList(GraphQLString),
|
||||
resolve({ id: _id }, arg, { authorization }) {
|
||||
if (!authorization) {
|
||||
return ({});
|
||||
}
|
||||
return new Promise((res, rej) => {
|
||||
axios({
|
||||
url: process.env.GATEWAY_ENDPOINT,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
{
|
||||
teams_TeamsByRole{
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
headers: { authorization },
|
||||
}).then(
|
||||
(result) => {
|
||||
const ret = [];
|
||||
Event.findOne({ _id }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
result.data.data.teams_TeamsByRole.forEach((team) => {
|
||||
if (!(event.participants.some(participant => participant.participantId === team.id))) {
|
||||
ret.push(team.id);
|
||||
}
|
||||
});
|
||||
res(ret);
|
||||
});
|
||||
},
|
||||
(error) => {
|
||||
rej(new ServiceUnavailableError(error));
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
invitations: {
|
||||
type: new GraphQLList(InvitationType),
|
||||
resolve(parent) {
|
||||
|
||||
Reference in new issue
Block a user