Skip to content

Commit d1b6ce8

Browse files
committed
oneFullBook
1 parent 395f0fb commit d1b6ce8

File tree

6 files changed

+87
-28
lines changed

6 files changed

+87
-28
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.2",
3+
"version": "0.1.3",
44
"description": "Automatically generated by graphql-editor-cli",
55
"main": "lib/index.js",
66
"scripts": {

packages/integrations/gei-bookings/schema.graphql

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,21 @@ type UserMutation{
6262
bookService(
6363
input: BookServiceInput!
6464
): BookServiceRespond!
65+
send(
66+
mailgunData: MailgunData!
67+
): String
6568
respondOnServiceRequest(
6669
input: RespondOnServiceRequestInput!
6770
): RespondOnServiceRequestRespond!
6871
}
6972

73+
input MailgunData{
74+
to: String!
75+
subject: String!
76+
message: String!
77+
from: String
78+
}
79+
7080
input GetBookingsForServiceInput{
7181
page: PageOptionsInput
7282
filters: GetBookingsForServiceFiltersInput
@@ -195,7 +205,7 @@ input BookServiceInput{
195205
}
196206

197207
type BookServiceRespond{
198-
books: [BookingRecord!]
208+
book: BookingRecord!
199209
error: GlobalError
200210
}
201211

@@ -223,7 +233,7 @@ type Service implements dbEssentials{
223233

224234
type BookingRecord implements dbEssentials{
225235
bookerId: String!
226-
service: Service!
236+
services: [Service!]
227237
comments: String
228238
_id: String!
229239
createdAt: Date!

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ export const bookService = async (input: FieldResolveInput) =>
2323
return service.value
2424
}))
2525

26-
const books = await o('Bookings')
27-
.collection.insertMany(services.map((service) =>(
26+
const book = await o('Bookings')
27+
.collection.insertOne(
2828
{
2929
_id: new ObjectId().toHexString(),
3030
createdAt: new Date(),
3131
bookerId: src.userId,
32-
service: service._id ,
32+
serviceIds: args.input.serviceIds,
3333
comments: args.input.comments ? args.input.comments : undefined,
34-
status: service.neededAccept ? BookStatus.PENDING : BookStatus.ACCEPTED,
35-
})))
36-
.then(async (c) => o('Bookings').collection.find({ _id: { $in: Object.values(c.insertedIds)} })?.toArray());
37-
if (!books) {
34+
status: services[0].neededAccept ? BookStatus.PENDING : BookStatus.ACCEPTED,
35+
})
36+
.then(async (c) => o('Bookings').collection.find({ _id: c.insertId } )?.toArray());
37+
if (!book) {
3838
throw new GlobalError('inserted document is null', import.meta.url);
3939
}
40-
return { books: await o('Bookings').composeRelated(books, 'service', 'Services', '_id') };
40+
return { book: { ...(await o('Bookings')).findOne({ _id: book.insertId }), services: services }};
4141
}),
4242
)(input.arguments, input.source);
4343
export default bookService;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const getSelfBooks = async (input: FieldResolveInput) =>
1515
.limit(po.limit)
1616
.sort('createdAt', -1)
1717
.toArray()
18-
.then(async (b) => await orm().then((o) => o('Bookings').composeRelated(b, 'service', 'Services', '_id')))),
18+
.then(async (b) => await orm().then((o) => o('Bookings').composeRelated(b, 'services', 'Services', '_id')))),
1919
}));
2020
}),
2121
)(input.arguments, input.source);

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ export const AllTypesProps: Record<string,any> = {
3333
bookService:{
3434
input:"BookServiceInput"
3535
},
36+
send:{
37+
mailgunData:"MailgunData"
38+
},
3639
respondOnServiceRequest:{
3740
input:"RespondOnServiceRequestInput"
3841
}
42+
},
43+
MailgunData:{
44+
3945
},
4046
GetBookingsForServiceInput:{
4147
page:"PageOptionsInput",
@@ -114,6 +120,7 @@ export const ReturnTypes: Record<string,any> = {
114120
updateService:"UpdateServiceRespond",
115121
removeService:"RemoveServiceRespond",
116122
bookService:"BookServiceRespond",
123+
send:"String",
117124
respondOnServiceRequest:"RespondOnServiceRequestRespond"
118125
},
119126
GetBookingsForServiceRespond:{
@@ -153,7 +160,7 @@ export const ReturnTypes: Record<string,any> = {
153160
error:"GlobalError"
154161
},
155162
BookServiceRespond:{
156-
books:"BookingRecord",
163+
book:"BookingRecord",
157164
error:"GlobalError"
158165
},
159166
UserServiceRespond:{
@@ -175,7 +182,7 @@ export const ReturnTypes: Record<string,any> = {
175182
},
176183
BookingRecord:{
177184
bookerId:"String",
178-
service:"Service",
185+
services:"Service",
179186
comments:"String",
180187
_id:"String",
181188
createdAt:"Date",

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

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ export const Thunder =
165165
operation: O,
166166
graphqlOptions?: ThunderGraphQLOptions<SCLR>,
167167
) =>
168-
<Z extends ValueTypes[R]>(o: Z | ValueTypes[R], ops?: OperationOptions & { variables?: Record<string, unknown> }) =>
168+
<Z extends ValueTypes[R]>(
169+
o: (Z & ValueTypes[R]) | ValueTypes[R],
170+
ops?: OperationOptions & { variables?: Record<string, unknown> },
171+
) =>
169172
fn(
170173
Zeus(operation, o, {
171174
operationOptions: ops,
@@ -194,7 +197,10 @@ export const SubscriptionThunder =
194197
operation: O,
195198
graphqlOptions?: ThunderGraphQLOptions<SCLR>,
196199
) =>
197-
<Z extends ValueTypes[R]>(o: Z | ValueTypes[R], ops?: OperationOptions & { variables?: ExtractVariables<Z> }) => {
200+
<Z extends ValueTypes[R]>(
201+
o: (Z & ValueTypes[R]) | ValueTypes[R],
202+
ops?: OperationOptions & { variables?: ExtractVariables<Z> },
203+
) => {
198204
const returnedFunction = fn(
199205
Zeus(operation, o, {
200206
operationOptions: ops,
@@ -230,7 +236,7 @@ export const Zeus = <
230236
R extends keyof ValueTypes = GenericOperation<O>,
231237
>(
232238
operation: O,
233-
o: Z | ValueTypes[R],
239+
o: (Z & ValueTypes[R]) | ValueTypes[R],
234240
ops?: {
235241
operationOptions?: OperationOptions;
236242
scalars?: ScalarDefinition;
@@ -700,7 +706,7 @@ type IsInterfaced<SRC extends DeepAnify<DST>, DST, SCLR extends ScalarDefinition
700706
[P in keyof SRC]: SRC[P] extends '__union' & infer R
701707
? P extends keyof DST
702708
? IsArray<R, '__typename' extends keyof DST ? DST[P] & { __typename: true } : DST[P], SCLR>
703-
: IsArray<R, '__typename' extends keyof DST ? { __typename: true } : never, SCLR>
709+
: IsArray<R, '__typename' extends keyof DST ? { __typename: true } : Record<string, never>, SCLR>
704710
: never;
705711
}[keyof SRC] & {
706712
[P in keyof Omit<
@@ -810,11 +816,18 @@ export type Variable<T extends GraphQLVariableType, Name extends string> = {
810816
' __zeus_type': T;
811817
};
812818

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+
813826
export type ExtractVariables<Query> = Query extends Variable<infer VType, infer VName>
814827
? { [key in VName]: GetVariableType<VType> }
815828
: Query extends [infer Inputs, infer Outputs]
816-
? ExtractVariables<Inputs> & ExtractVariables<Outputs>
817-
: Query extends string | number | boolean
829+
? ExtractVariablesDeep<Inputs> & ExtractVariables<Outputs>
830+
: Query extends string | number | boolean | Array<string | number | boolean>
818831
? // eslint-disable-next-line @typescript-eslint/ban-types
819832
{}
820833
: UnionToIntersection<{ [K in keyof Query]: WithOptionalNullables<ExtractVariables<Query[K]>> }[keyof Query]>;
@@ -867,9 +880,16 @@ registerService?: [{ input: ValueTypes["RegisterServiceInput"] | Variable<any, s
867880
updateService?: [{ input: Array<ValueTypes["UpdateServiceInput"]> | Variable<any, string>},ValueTypes["UpdateServiceRespond"]],
868881
removeService?: [{ serviceId: string | Variable<any, string>},ValueTypes["RemoveServiceRespond"]],
869882
bookService?: [{ input: ValueTypes["BookServiceInput"] | Variable<any, string>},ValueTypes["BookServiceRespond"]],
883+
send?: [{ mailgunData: ValueTypes["MailgunData"] | Variable<any, string>},boolean | `@${string}`],
870884
respondOnServiceRequest?: [{ input: ValueTypes["RespondOnServiceRequestInput"] | Variable<any, string>},ValueTypes["RespondOnServiceRequestRespond"]],
871885
__typename?: boolean | `@${string}`
872886
}>;
887+
["MailgunData"]: {
888+
to: string | Variable<any, string>,
889+
subject: string | Variable<any, string>,
890+
message: string | Variable<any, string>,
891+
from?: string | undefined | null | Variable<any, string>
892+
};
873893
["GetBookingsForServiceInput"]: {
874894
page?: ValueTypes["PageOptionsInput"] | undefined | null | Variable<any, string>,
875895
filters?: ValueTypes["GetBookingsForServiceFiltersInput"] | undefined | null | Variable<any, string>
@@ -980,7 +1000,7 @@ respondOnServiceRequest?: [{ input: ValueTypes["RespondOnServiceRequestInput"] |
9801000
comments?: string | undefined | null | Variable<any, string>
9811001
};
9821002
["BookServiceRespond"]: AliasType<{
983-
books?:ValueTypes["BookingRecord"],
1003+
book?:ValueTypes["BookingRecord"],
9841004
error?:ValueTypes["GlobalError"],
9851005
__typename?: boolean | `@${string}`
9861006
}>;
@@ -1006,7 +1026,7 @@ respondOnServiceRequest?: [{ input: ValueTypes["RespondOnServiceRequestInput"] |
10061026
}>;
10071027
["BookingRecord"]: AliasType<{
10081028
bookerId?:boolean | `@${string}`,
1009-
service?:ValueTypes["Service"],
1029+
services?:ValueTypes["Service"],
10101030
comments?:boolean | `@${string}`,
10111031
_id?:boolean | `@${string}`,
10121032
createdAt?:boolean | `@${string}`,
@@ -1082,9 +1102,16 @@ registerService?: [{ input: ResolverInputTypes["RegisterServiceInput"]},Resolver
10821102
updateService?: [{ input: Array<ResolverInputTypes["UpdateServiceInput"]>},ResolverInputTypes["UpdateServiceRespond"]],
10831103
removeService?: [{ serviceId: string},ResolverInputTypes["RemoveServiceRespond"]],
10841104
bookService?: [{ input: ResolverInputTypes["BookServiceInput"]},ResolverInputTypes["BookServiceRespond"]],
1105+
send?: [{ mailgunData: ResolverInputTypes["MailgunData"]},boolean | `@${string}`],
10851106
respondOnServiceRequest?: [{ input: ResolverInputTypes["RespondOnServiceRequestInput"]},ResolverInputTypes["RespondOnServiceRequestRespond"]],
10861107
__typename?: boolean | `@${string}`
10871108
}>;
1109+
["MailgunData"]: {
1110+
to: string,
1111+
subject: string,
1112+
message: string,
1113+
from?: string | undefined | null
1114+
};
10881115
["GetBookingsForServiceInput"]: {
10891116
page?: ResolverInputTypes["PageOptionsInput"] | undefined | null,
10901117
filters?: ResolverInputTypes["GetBookingsForServiceFiltersInput"] | undefined | null
@@ -1195,7 +1222,7 @@ respondOnServiceRequest?: [{ input: ResolverInputTypes["RespondOnServiceRequestI
11951222
comments?: string | undefined | null
11961223
};
11971224
["BookServiceRespond"]: AliasType<{
1198-
books?:ResolverInputTypes["BookingRecord"],
1225+
book?:ResolverInputTypes["BookingRecord"],
11991226
error?:ResolverInputTypes["GlobalError"],
12001227
__typename?: boolean | `@${string}`
12011228
}>;
@@ -1221,7 +1248,7 @@ respondOnServiceRequest?: [{ input: ResolverInputTypes["RespondOnServiceRequestI
12211248
}>;
12221249
["BookingRecord"]: AliasType<{
12231250
bookerId?:boolean | `@${string}`,
1224-
service?:ResolverInputTypes["Service"],
1251+
services?:ResolverInputTypes["Service"],
12251252
comments?:boolean | `@${string}`,
12261253
_id?:boolean | `@${string}`,
12271254
createdAt?:boolean | `@${string}`,
@@ -1301,7 +1328,14 @@ in otherwise any endpoint in UserMutation will throw error about malformed sourc
13011328
updateService: ModelTypes["UpdateServiceRespond"],
13021329
removeService: ModelTypes["RemoveServiceRespond"],
13031330
bookService: ModelTypes["BookServiceRespond"],
1331+
send?: string | undefined,
13041332
respondOnServiceRequest: ModelTypes["RespondOnServiceRequestRespond"]
1333+
};
1334+
["MailgunData"]: {
1335+
to: string,
1336+
subject: string,
1337+
message: string,
1338+
from?: string | undefined
13051339
};
13061340
["GetBookingsForServiceInput"]: {
13071341
page?: ModelTypes["PageOptionsInput"] | undefined,
@@ -1404,7 +1438,7 @@ in otherwise any endpoint in UserMutation will throw error about malformed sourc
14041438
comments?: string | undefined
14051439
};
14061440
["BookServiceRespond"]: {
1407-
books?: Array<ModelTypes["BookingRecord"]> | undefined,
1441+
book: ModelTypes["BookingRecord"],
14081442
error?: ModelTypes["GlobalError"] | undefined
14091443
};
14101444
["UserServiceRespond"]: {
@@ -1427,7 +1461,7 @@ in otherwise any endpoint in UserMutation will throw error about malformed sourc
14271461
};
14281462
["BookingRecord"]: {
14291463
bookerId: string,
1430-
service: ModelTypes["Service"],
1464+
services?: Array<ModelTypes["Service"]> | undefined,
14311465
comments?: string | undefined,
14321466
_id: string,
14331467
createdAt: ModelTypes["Date"],
@@ -1503,7 +1537,14 @@ in otherwise any endpoint in UserMutation will throw error about malformed sourc
15031537
updateService: GraphQLTypes["UpdateServiceRespond"],
15041538
removeService: GraphQLTypes["RemoveServiceRespond"],
15051539
bookService: GraphQLTypes["BookServiceRespond"],
1540+
send?: string | undefined,
15061541
respondOnServiceRequest: GraphQLTypes["RespondOnServiceRequestRespond"]
1542+
};
1543+
["MailgunData"]: {
1544+
to: string,
1545+
subject: string,
1546+
message: string,
1547+
from?: string | undefined
15071548
};
15081549
["GetBookingsForServiceInput"]: {
15091550
page?: GraphQLTypes["PageOptionsInput"] | undefined,
@@ -1616,7 +1657,7 @@ in otherwise any endpoint in UserMutation will throw error about malformed sourc
16161657
};
16171658
["BookServiceRespond"]: {
16181659
__typename: "BookServiceRespond",
1619-
books?: Array<GraphQLTypes["BookingRecord"]> | undefined,
1660+
book: GraphQLTypes["BookingRecord"],
16201661
error?: GraphQLTypes["GlobalError"] | undefined
16211662
};
16221663
["UserServiceRespond"]: {
@@ -1642,7 +1683,7 @@ in otherwise any endpoint in UserMutation will throw error about malformed sourc
16421683
["BookingRecord"]: {
16431684
__typename: "BookingRecord",
16441685
bookerId: string,
1645-
service: GraphQLTypes["Service"],
1686+
services?: Array<GraphQLTypes["Service"]> | undefined,
16461687
comments?: string | undefined,
16471688
_id: string,
16481689
createdAt: GraphQLTypes["Date"],
@@ -1693,6 +1734,7 @@ export const enum ServiceType {
16931734
}
16941735

16951736
type ZEUS_VARIABLES = {
1737+
["MailgunData"]: ValueTypes["MailgunData"];
16961738
["GetBookingsForServiceInput"]: ValueTypes["GetBookingsForServiceInput"];
16971739
["GetBookingsForServiceFiltersInput"]: ValueTypes["GetBookingsForServiceFiltersInput"];
16981740
["RespondOnServiceRequestInput"]: ValueTypes["RespondOnServiceRequestInput"];

0 commit comments

Comments
 (0)