Artur Malak
01/01/2019, 6:55 PMArtur Malak
01/01/2019, 7:49 PMasync updateBoxName(parent, args, context) {
const { boxId, name } = args;
const id = getUserId(context);
const userBoxes = (await context.prisma.user({ id }).boxes()).map(box => box.id);
if(!userBoxes.includes(boxId)) throw new Error('It is not your box.');
return context.prisma.user({ id }).updateBox({
where: { id: boxId },
data: { name }
});
},
Artur Malak
01/01/2019, 7:53 PMboxes(parent, args, context) {
const id = getUserId(context);
const where = args.filter ? {
OR: [
{ name_contains: args.filter },
{ owner: { name_contains: args.filter } }
]
} : {};
return context.prisma.user({ id }).boxes({ where });
}
Harshit
01/02/2019, 3:47 AM