Skip to content

Commit ff7ee22

Browse files
committed
fixBooks
1 parent d1b6ce8 commit ff7ee22

File tree

7 files changed

+26
-38
lines changed

7 files changed

+26
-38
lines changed

package-lock.json

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/integrations/gei-bookings/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
"dotenv-cli": "^7.0.0",
2222
"fetch": "^1.1.0",
2323
"form-data": "^4.0.0",
24-
"graphql-editor-cli": "^0.9.0",
24+
"graphql-editor-cli": "^0.9.1",
2525
"i-graphql": "^0.1.2",
2626
"mongodb": "^5.1.0",
2727
"node-fetch": "^3.3.0",
28-
"stucco-js": "^0.10.18",
28+
"stucco-js": "^0.10.19",
2929
"ws": "^8.16.0"
3030
},
3131
"devDependencies": {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ export const bookService = async (input: FieldResolveInput) =>
2929
_id: new ObjectId().toHexString(),
3030
createdAt: new Date(),
3131
bookerId: src.userId,
32-
serviceIds: args.input.serviceIds,
32+
services: args.input.serviceIds,
3333
comments: args.input.comments ? args.input.comments : undefined,
3434
status: services[0].neededAccept ? BookStatus.PENDING : BookStatus.ACCEPTED,
3535
})
36-
.then(async (c) => o('Bookings').collection.find({ _id: c.insertId } )?.toArray());
36+
.then(async (c) => o('Bookings').collection.findOne({ _id: c.insertedId } ));
3737
if (!book) {
3838
throw new GlobalError('inserted document is null', import.meta.url);
3939
}
40-
return { book: { ...(await o('Bookings')).findOne({ _id: book.insertId }), services: services }};
40+
return { book: { ...book, services: services }};
4141
}),
4242
)(input.arguments, input.source);
4343
export default bookService;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ export const respondOnServiceRequest = async (input: FieldResolveInput) =>
1313
const o = await orm();
1414
await o('Bookings')
1515
.collection.find({ _id: { $in: args.input.bookIds }, answeredAt: { $exists: false } }).toArray()
16-
.then(async (b) => {
17-
if (!b || b.length < 1) {
16+
.then(async (books) => {
17+
if (!books || books.length < 1) {
1818
throw new GlobalError(`cannot find anyone books for id: ${ args.input.bookIds }`, import.meta.url);
1919
}
2020
await o('Services')
21-
.collection.findOne({ _id: {$in: b.map((b) => b.service)}, ownerId: src.userId || src._id})
22-
.then((r) => {
23-
if (!r || b.length < 1) {
21+
.collection.find({ _id: { $in: books.map((b)=> b.services ).flatMap(innerArray => innerArray) }, ownerId: src.userId || src._id})
22+
.toArray().then((r) => {
23+
if (!r || r.length < 1) {
2424
throw new GlobalError('you can answer only on yours services', import.meta.url);
2525
}
2626
});

packages/integrations/gei-bookings/src/UserQuery/getBookingsForService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const getBookingsForService = async (input: FieldResolveInput) =>
2323
.sort('createdAt', -1)
2424
.toArray()
2525

26-
return { books: convertDateObjToStringForArray<BookingRecordModel>(await o('Bookings').composeRelated(bookings, 'service', 'Services', '_id')) }
26+
return { books: convertDateObjToStringForArray<BookingRecordModel>(await o('Bookings').composeRelated(bookings, 'services', 'Services', '_id')) }
2727
}),
2828
)(input.arguments, input.source);
2929
export default getBookingsForService;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ModelTypes } from '../zeus/index.js';
22

3-
export type BookingRecordModel = Omit<ModelTypes['BookingRecord'], 'service'> & {
4-
service: string;
3+
export type BookingRecordModel = Omit<ModelTypes['BookingRecord'], 'services'> & {
4+
services: string[];
55
};

packages/integrations/gei-bookings/src/zeus/index.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ export const Thunder =
165165
operation: O,
166166
graphqlOptions?: ThunderGraphQLOptions<SCLR>,
167167
) =>
168-
<Z extends ValueTypes[R]>(
169-
o: (Z & ValueTypes[R]) | ValueTypes[R],
170-
ops?: OperationOptions & { variables?: Record<string, unknown> },
171-
) =>
168+
<Z extends ValueTypes[R]>(o: Z | ValueTypes[R], ops?: OperationOptions & { variables?: Record<string, unknown> }) =>
172169
fn(
173170
Zeus(operation, o, {
174171
operationOptions: ops,
@@ -197,10 +194,7 @@ export const SubscriptionThunder =
197194
operation: O,
198195
graphqlOptions?: ThunderGraphQLOptions<SCLR>,
199196
) =>
200-
<Z extends ValueTypes[R]>(
201-
o: (Z & ValueTypes[R]) | ValueTypes[R],
202-
ops?: OperationOptions & { variables?: ExtractVariables<Z> },
203-
) => {
197+
<Z extends ValueTypes[R]>(o: Z | ValueTypes[R], ops?: OperationOptions & { variables?: ExtractVariables<Z> }) => {
204198
const returnedFunction = fn(
205199
Zeus(operation, o, {
206200
operationOptions: ops,
@@ -236,7 +230,7 @@ export const Zeus = <
236230
R extends keyof ValueTypes = GenericOperation<O>,
237231
>(
238232
operation: O,
239-
o: (Z & ValueTypes[R]) | ValueTypes[R],
233+
o: Z | ValueTypes[R],
240234
ops?: {
241235
operationOptions?: OperationOptions;
242236
scalars?: ScalarDefinition;
@@ -706,7 +700,7 @@ type IsInterfaced<SRC extends DeepAnify<DST>, DST, SCLR extends ScalarDefinition
706700
[P in keyof SRC]: SRC[P] extends '__union' & infer R
707701
? P extends keyof DST
708702
? IsArray<R, '__typename' extends keyof DST ? DST[P] & { __typename: true } : DST[P], SCLR>
709-
: IsArray<R, '__typename' extends keyof DST ? { __typename: true } : Record<string, never>, SCLR>
703+
: IsArray<R, '__typename' extends keyof DST ? { __typename: true } : never, SCLR>
710704
: never;
711705
}[keyof SRC] & {
712706
[P in keyof Omit<
@@ -816,18 +810,11 @@ export type Variable<T extends GraphQLVariableType, Name extends string> = {
816810
' __zeus_type': T;
817811
};
818812

819-
export type ExtractVariablesDeep<Query> = Query extends Variable<infer VType, infer VName>
820-
? { [key in VName]: GetVariableType<VType> }
821-
: Query extends string | number | boolean | Array<string | number | boolean>
822-
? // eslint-disable-next-line @typescript-eslint/ban-types
823-
{}
824-
: UnionToIntersection<{ [K in keyof Query]: WithOptionalNullables<ExtractVariablesDeep<Query[K]>> }[keyof Query]>;
825-
826813
export type ExtractVariables<Query> = Query extends Variable<infer VType, infer VName>
827814
? { [key in VName]: GetVariableType<VType> }
828815
: Query extends [infer Inputs, infer Outputs]
829-
? ExtractVariablesDeep<Inputs> & ExtractVariables<Outputs>
830-
: Query extends string | number | boolean | Array<string | number | boolean>
816+
? ExtractVariables<Inputs> & ExtractVariables<Outputs>
817+
: Query extends string | number | boolean
831818
? // eslint-disable-next-line @typescript-eslint/ban-types
832819
{}
833820
: UnionToIntersection<{ [K in keyof Query]: WithOptionalNullables<ExtractVariables<Query[K]>> }[keyof Query]>;

0 commit comments

Comments
 (0)