Skip to content

Commit 578be5f

Browse files
committed
fixForServisUpdate
1 parent 3ab5227 commit 578be5f

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

packages/integrations/gei-bookings/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gei-bookings",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Automatically generated by graphql-editor-cli",
55
"main": "lib/index.js",
66
"scripts": {

packages/integrations/gei-bookings/src/UserMutation/registerService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ resolverFor('UserMutation', 'registerService', async (args, src) =>
1515
throw new GlobalError('start date cannot start in past', import.meta.url);
1616
}
1717
return {
18+
...args.input,
1819
_id: new ObjectId().toHexString(),
1920
createdAt: new Date(),
2021
startDate: new Date(String(startDate)),

packages/integrations/gei-bookings/src/UserMutation/updateService.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,34 @@ export const updateService = async (input: FieldResolveInput) =>
99
errMiddleware(
1010
async () => (
1111
sourceContainUserIdOrThrow(src),
12-
Promise.all(args.input.map(async (updateSet) =>
13-
await orm().then((o) =>
12+
Promise.all(args.input.map(async (updateSet) => {
13+
const entries = Object.entries(updateSet || {});
14+
const reconstructedObject: Record<string, any> = {};
15+
16+
const entriesWithOutId = entries.filter(([key, value]) => key !== 'serviceId' && value !== undefined && value !== null);
17+
if (!entriesWithOutId) {
18+
throw new Error(`You need update input argument for this resolver to work`);
19+
}
20+
21+
entriesWithOutId.forEach((entry) => {
22+
const [key, value] = entry;
23+
reconstructedObject[key] = value;
24+
});
25+
return await orm().then((o) =>
1426
o('Services')
1527
.collection.updateOne(
16-
{ _id: updateSet.serviceId, ownerId: src.userId || src._id, taken: { $ne: true }, active: { $ne: true } },
17-
{$set:
28+
{ _id: updateSet.serviceId, ownerId: src.userId || src._id, taken: { $ne: true } },
29+
{ $set:
1830
{
19-
...Object.fromEntries(Object.entries({...updateSet, startDate: updateSet.startDate? new Date(updateSet.startDate as string) : undefined }).filter((e) => e !== null)),
20-
updatedAt: new Date,
21-
}},
31+
...reconstructedObject,
32+
startDate: updateSet.startDate ? new Date(updateSet.startDate as string) : undefined,
33+
updatedAt: new Date(),
34+
},
35+
},
2236
)
23-
24-
)
25-
)).then(async (u) => u && { service: convertDateObjToStringForArray(await mustFindAny(ServicesCollection, { _id: { $in: args.input.map((up)=>up.serviceId) } })) })
37+
)
38+
}
39+
)).then(async (u) => u && { service: convertDateObjToStringForArray(await mustFindAny(ServicesCollection, { _id: { $in: args.input.map((up)=> up.serviceId) }})) })
2640
),
2741
),
2842

packages/integrations/gei-crud/src/Mutation/update.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const update = async (input: FieldResolveInput & Partial<DataInput>) =>
3131
typeof entriesWithOutId[0][1] === 'object' && !Array.isArray(entriesWithOutId[0][1])
3232
? entriesWithOutId[0][1]
3333
: reconstructedObject;
34-
console.log(setter);
3534
const filterInput: Record<string, any> = { _id, ...prepareSourceParameters(input) };
3635
const res = await db(input.data?.model || prepareModel(input)).collection.updateOne(filterInput, {
3736
$set: { ...setter, ...(input.data?.addFields && createObjectFromAddFields(input.data.addFields)), updatedAt: new Date().toISOString() },

0 commit comments

Comments
 (0)