Skip to content

Commit

Permalink
fixBooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbrui committed Mar 28, 2024
1 parent d1b6ce8 commit ff7ee22
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 38 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/integrations/gei-bookings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"dotenv-cli": "^7.0.0",
"fetch": "^1.1.0",
"form-data": "^4.0.0",
"graphql-editor-cli": "^0.9.0",
"graphql-editor-cli": "^0.9.1",
"i-graphql": "^0.1.2",
"mongodb": "^5.1.0",
"node-fetch": "^3.3.0",
"stucco-js": "^0.10.18",
"stucco-js": "^0.10.19",
"ws": "^8.16.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export const bookService = async (input: FieldResolveInput) =>
_id: new ObjectId().toHexString(),
createdAt: new Date(),
bookerId: src.userId,
serviceIds: args.input.serviceIds,
services: args.input.serviceIds,
comments: args.input.comments ? args.input.comments : undefined,
status: services[0].neededAccept ? BookStatus.PENDING : BookStatus.ACCEPTED,
})
.then(async (c) => o('Bookings').collection.find({ _id: c.insertId } )?.toArray());
.then(async (c) => o('Bookings').collection.findOne({ _id: c.insertedId } ));
if (!book) {
throw new GlobalError('inserted document is null', import.meta.url);
}
return { book: { ...(await o('Bookings')).findOne({ _id: book.insertId }), services: services }};
return { book: { ...book, services: services }};
}),
)(input.arguments, input.source);
export default bookService;
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export const respondOnServiceRequest = async (input: FieldResolveInput) =>
const o = await orm();
await o('Bookings')
.collection.find({ _id: { $in: args.input.bookIds }, answeredAt: { $exists: false } }).toArray()
.then(async (b) => {
if (!b || b.length < 1) {
.then(async (books) => {
if (!books || books.length < 1) {
throw new GlobalError(`cannot find anyone books for id: ${ args.input.bookIds }`, import.meta.url);
}
await o('Services')
.collection.findOne({ _id: {$in: b.map((b) => b.service)}, ownerId: src.userId || src._id})
.then((r) => {
if (!r || b.length < 1) {
.collection.find({ _id: { $in: books.map((b)=> b.services ).flatMap(innerArray => innerArray) }, ownerId: src.userId || src._id})
.toArray().then((r) => {
if (!r || r.length < 1) {
throw new GlobalError('you can answer only on yours services', import.meta.url);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const getBookingsForService = async (input: FieldResolveInput) =>
.sort('createdAt', -1)
.toArray()

return { books: convertDateObjToStringForArray<BookingRecordModel>(await o('Bookings').composeRelated(bookings, 'service', 'Services', '_id')) }
return { books: convertDateObjToStringForArray<BookingRecordModel>(await o('Bookings').composeRelated(bookings, 'services', 'Services', '_id')) }
}),
)(input.arguments, input.source);
export default getBookingsForService;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ModelTypes } from '../zeus/index.js';

export type BookingRecordModel = Omit<ModelTypes['BookingRecord'], 'service'> & {
service: string;
export type BookingRecordModel = Omit<ModelTypes['BookingRecord'], 'services'> & {
services: string[];
};
25 changes: 6 additions & 19 deletions packages/integrations/gei-bookings/src/zeus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ export const Thunder =
operation: O,
graphqlOptions?: ThunderGraphQLOptions<SCLR>,
) =>
<Z extends ValueTypes[R]>(
o: (Z & ValueTypes[R]) | ValueTypes[R],
ops?: OperationOptions & { variables?: Record<string, unknown> },
) =>
<Z extends ValueTypes[R]>(o: Z | ValueTypes[R], ops?: OperationOptions & { variables?: Record<string, unknown> }) =>
fn(
Zeus(operation, o, {
operationOptions: ops,
Expand Down Expand Up @@ -197,10 +194,7 @@ export const SubscriptionThunder =
operation: O,
graphqlOptions?: ThunderGraphQLOptions<SCLR>,
) =>
<Z extends ValueTypes[R]>(
o: (Z & ValueTypes[R]) | ValueTypes[R],
ops?: OperationOptions & { variables?: ExtractVariables<Z> },
) => {
<Z extends ValueTypes[R]>(o: Z | ValueTypes[R], ops?: OperationOptions & { variables?: ExtractVariables<Z> }) => {
const returnedFunction = fn(
Zeus(operation, o, {
operationOptions: ops,
Expand Down Expand Up @@ -236,7 +230,7 @@ export const Zeus = <
R extends keyof ValueTypes = GenericOperation<O>,
>(
operation: O,
o: (Z & ValueTypes[R]) | ValueTypes[R],
o: Z | ValueTypes[R],
ops?: {
operationOptions?: OperationOptions;
scalars?: ScalarDefinition;
Expand Down Expand Up @@ -706,7 +700,7 @@ type IsInterfaced<SRC extends DeepAnify<DST>, DST, SCLR extends ScalarDefinition
[P in keyof SRC]: SRC[P] extends '__union' & infer R
? P extends keyof DST
? IsArray<R, '__typename' extends keyof DST ? DST[P] & { __typename: true } : DST[P], SCLR>
: IsArray<R, '__typename' extends keyof DST ? { __typename: true } : Record<string, never>, SCLR>
: IsArray<R, '__typename' extends keyof DST ? { __typename: true } : never, SCLR>
: never;
}[keyof SRC] & {
[P in keyof Omit<
Expand Down Expand Up @@ -816,18 +810,11 @@ export type Variable<T extends GraphQLVariableType, Name extends string> = {
' __zeus_type': T;
};

export type ExtractVariablesDeep<Query> = Query extends Variable<infer VType, infer VName>
? { [key in VName]: GetVariableType<VType> }
: Query extends string | number | boolean | Array<string | number | boolean>
? // eslint-disable-next-line @typescript-eslint/ban-types
{}
: UnionToIntersection<{ [K in keyof Query]: WithOptionalNullables<ExtractVariablesDeep<Query[K]>> }[keyof Query]>;

export type ExtractVariables<Query> = Query extends Variable<infer VType, infer VName>
? { [key in VName]: GetVariableType<VType> }
: Query extends [infer Inputs, infer Outputs]
? ExtractVariablesDeep<Inputs> & ExtractVariables<Outputs>
: Query extends string | number | boolean | Array<string | number | boolean>
? ExtractVariables<Inputs> & ExtractVariables<Outputs>
: Query extends string | number | boolean
? // eslint-disable-next-line @typescript-eslint/ban-types
{}
: UnionToIntersection<{ [K in keyof Query]: WithOptionalNullables<ExtractVariables<Query[K]>> }[keyof Query]>;
Expand Down

0 comments on commit ff7ee22

Please sign in to comment.