@driveflux/api-functions 1.0.54 → 1.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/auth/confirm.js +24 -29
  2. package/dist/auth/emails.js +12 -13
  3. package/dist/auth/formatter.js +5 -5
  4. package/dist/auth/otp.js +66 -50
  5. package/dist/auth/register.js +42 -34
  6. package/dist/auth/tokens.js +58 -55
  7. package/dist/auth/verifications.js +53 -52
  8. package/dist/constants.js +0 -1
  9. package/dist/create-logger.js +1 -2
  10. package/dist/mailjet/calls/manage-contacts-in-list.js +5 -6
  11. package/dist/mailjet/calls/manage-subscription-status.js +4 -5
  12. package/dist/mailjet/calls/request-service.js +7 -6
  13. package/dist/mailjet/refresh-email-preferences.js +11 -12
  14. package/dist/mailjet/set-contact.js +11 -12
  15. package/dist/mailjet/types.js +1 -2
  16. package/dist/mailjet/utils/convert-to-array.js +8 -6
  17. package/dist/mailjet/utils/extract-email-preferences.js +14 -15
  18. package/dist/mailjet/utils/lists.js +7 -8
  19. package/dist/mailjet/utils/update-email-references.js +16 -15
  20. package/dist/notion/client.js +22 -19
  21. package/dist/notion/helpful.js +6 -9
  22. package/dist/notion/schemas/block.js +42 -48
  23. package/dist/notion/schemas/common.js +9 -14
  24. package/dist/notion/schemas/database.js +62 -60
  25. package/dist/notion/schemas/emoji.js +1 -2
  26. package/dist/notion/schemas/file.js +9 -9
  27. package/dist/notion/schemas/kb.js +5 -6
  28. package/dist/notion/schemas/page.js +72 -61
  29. package/dist/notion/schemas/parent.js +4 -5
  30. package/dist/notion/schemas/user.js +18 -19
  31. package/dist/reservation/agree.js +6 -7
  32. package/dist/reservation/checks.js +3 -4
  33. package/dist/reservation/display-vehicle.js +65 -71
  34. package/dist/reservation/ensure-user-billing-address.js +9 -11
  35. package/dist/reservation/fetch-or-create.js +48 -54
  36. package/dist/reservation/invoice.js +70 -78
  37. package/dist/reservation/payer.js +5 -6
  38. package/dist/reservation/payment-intent-sync.js +4 -6
  39. package/dist/reservation/reserve.js +3 -4
  40. package/dist/reservation/types.js +1 -2
  41. package/dist/reservation/vehicle.js +13 -16
  42. package/dist/slack.js +24 -29
  43. package/dist/validation.js +77 -79
  44. package/dist/vehicle/vehicle-pricing/constants.js +22 -19
  45. package/dist/vehicle/vehicle-pricing/index.js +28 -42
  46. package/dist/vehicle/vehicle-pricing/types.js +1 -2
  47. package/package.json +3 -3
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { notionDatabasePropertyCheckboxSchema, notionDatabasePropertyCreatedBySchema, notionDatabasePropertyCreatedTimeSchema, notionDatabasePropertyDateSchema, notionDatabasePropertyFormulaSchema, notionDatabasePropertyLastEditedBySchema, notionDatabasePropertyLastEditedTimeSchema, notionDatabasePropertyMultiSelectSchema, notionDatabasePropertyNumberSchema, notionDatabasePropertyRelationSchema, notionDatabasePropertySelectSchema, notionDatabasePropertyStatusSchema, notionDatabasePropertyTitleSchema, notionDatabasePropertyUniqueIdSchema, notionDatabaseSchema, } from './database.js';
3
- import { notionPagePropertyCheckboxSchema, notionPagePropertyCreatedBySchema, notionPagePropertyCreatedTimeSchema, notionPagePropertyDateSchema, notionPagePropertyFormulaSchema, notionPagePropertyLastEditedBySchema, notionPagePropertyLastEditedTimeSchema, notionPagePropertyMultiSelectSchema, notionPagePropertyNumberSchema, notionPagePropertyRelationSchema, notionPagePropertyRichTextSchema, notionPagePropertySelectSchema, notionPagePropertyStatusSchema, notionPagePropertyTitleSchema, notionPagePropertyUniqueIdSchema, notionPageSchema, notionPagesSchema, } from './page.js';
2
+ import { notionDatabasePropertyCheckboxSchema, notionDatabasePropertyCreatedBySchema, notionDatabasePropertyCreatedTimeSchema, notionDatabasePropertyDateSchema, notionDatabasePropertyFormulaSchema, notionDatabasePropertyLastEditedBySchema, notionDatabasePropertyLastEditedTimeSchema, notionDatabasePropertyMultiSelectSchema, notionDatabasePropertyNumberSchema, notionDatabasePropertyRelationSchema, notionDatabasePropertySelectSchema, notionDatabasePropertyStatusSchema, notionDatabasePropertyTitleSchema, notionDatabasePropertyUniqueIdSchema, notionDatabaseSchema } from './database.js';
3
+ import { notionPagePropertyCheckboxSchema, notionPagePropertyCreatedBySchema, notionPagePropertyCreatedTimeSchema, notionPagePropertyDateSchema, notionPagePropertyFormulaSchema, notionPagePropertyLastEditedBySchema, notionPagePropertyLastEditedTimeSchema, notionPagePropertyMultiSelectSchema, notionPagePropertyNumberSchema, notionPagePropertyRelationSchema, notionPagePropertyRichTextSchema, notionPagePropertySelectSchema, notionPagePropertyStatusSchema, notionPagePropertyTitleSchema, notionPagePropertyUniqueIdSchema, notionPageSchema, notionPagesSchema } from './page.js';
4
4
  export const knowledgeBaseRetrieveDatabaseSchema = notionDatabaseSchema(z.object({
5
5
  Title: notionDatabasePropertyTitleSchema,
6
6
  Status: notionDatabasePropertyStatusSchema,
@@ -22,7 +22,7 @@ export const knowledgeBaseRetrieveDatabaseSchema = notionDatabaseSchema(z.object
22
22
  'Section Slug': notionDatabasePropertyFormulaSchema,
23
23
  'Topic Slug': notionDatabasePropertyFormulaSchema,
24
24
  Helpful: notionDatabasePropertyNumberSchema,
25
- Unhelpful: notionDatabasePropertyNumberSchema,
25
+ Unhelpful: notionDatabasePropertyNumberSchema
26
26
  }));
27
27
  export const knowledgeBaseRetrievePageSchema = notionPageSchema(z.object({
28
28
  Title: notionPagePropertyTitleSchema,
@@ -46,7 +46,7 @@ export const knowledgeBaseRetrievePageSchema = notionPageSchema(z.object({
46
46
  'Section Slug': notionPagePropertyFormulaSchema,
47
47
  'Topic Slug': notionPagePropertyFormulaSchema,
48
48
  Helpful: notionPagePropertyNumberSchema,
49
- Unhelpful: notionPagePropertyNumberSchema,
49
+ Unhelpful: notionPagePropertyNumberSchema
50
50
  }));
51
51
  export const knowledgeBaseQueryDatabaseSchema = notionPagesSchema(z.object({
52
52
  Title: notionPagePropertyTitleSchema,
@@ -69,6 +69,5 @@ export const knowledgeBaseQueryDatabaseSchema = notionPagesSchema(z.object({
69
69
  'Section Slug': notionPagePropertyFormulaSchema,
70
70
  'Topic Slug': notionPagePropertyFormulaSchema,
71
71
  Helpful: notionPagePropertyNumberSchema,
72
- Unhelpful: notionPagePropertyNumberSchema,
72
+ Unhelpful: notionPagePropertyNumberSchema
73
73
  }));
74
- //# sourceMappingURL=kb.js.map
@@ -1,78 +1,83 @@
1
1
  import { z } from 'zod';
2
2
  import { notionRichTextSchema } from './block.js';
3
- import { commonPropertyValues, notionCommonColorEnum, notionDateFormat, notionDateSchema, notionTimeFormat, } from './common.js';
3
+ import { commonPropertyValues, notionCommonColorEnum, notionDateFormat, notionDateSchema, notionTimeFormat } from './common.js';
4
4
  import { notionEmojiSchema } from './emoji.js';
5
5
  import { notionFileSchema } from './file.js';
6
6
  import { notionDatabaseParentSchema } from './parent.js';
7
7
  import { notionPartialUserSchema, notionUserSchema } from './user.js';
8
8
  export const notionPagePropertyCheckboxSchema = z.object({
9
9
  ...commonPropertyValues('checkbox'),
10
- checkbox: z.boolean(),
10
+ checkbox: z.boolean()
11
11
  });
12
12
  export const notionPagePropertyCreatedBySchema = z.object({
13
13
  ...commonPropertyValues('created_by'),
14
- created_by: notionUserSchema,
14
+ created_by: notionUserSchema
15
15
  });
16
16
  export const notionPagePropertyCreatedTimeSchema = z.object({
17
17
  ...commonPropertyValues('created_time'),
18
- created_time: notionTimeFormat,
18
+ created_time: notionTimeFormat
19
19
  });
20
20
  export const notionPagePropertyDateSchema = z.object({
21
21
  ...commonPropertyValues('date'),
22
- date: notionDateSchema.nullable(),
22
+ date: notionDateSchema.nullable()
23
23
  });
24
24
  export const notionPagePropertyEmailSchema = z.object({
25
25
  ...commonPropertyValues('email'),
26
- email: z.string(),
26
+ email: z.string()
27
27
  });
28
28
  export const notionPagePropertyFilesSchema = z.object({
29
29
  ...commonPropertyValues('files'),
30
- files: z.array(notionFileSchema),
30
+ files: z.array(notionFileSchema)
31
31
  });
32
32
  export const notionPagePropertyFormulaSchema = z.object({
33
33
  ...commonPropertyValues('formula'),
34
34
  formula: z.object({
35
- type: z.enum(['boolean', 'date', 'number', 'string']),
35
+ type: z.enum([
36
+ 'boolean',
37
+ 'date',
38
+ 'number',
39
+ 'string'
40
+ ]),
36
41
  boolean: z.boolean().optional(),
37
42
  date: notionDateFormat.optional(),
38
43
  number: z.number().optional(),
39
- string: z.string().optional(),
40
- }),
44
+ string: z.string().optional()
45
+ })
41
46
  });
42
47
  export const notionPagePropertyLastEditedBySchema = z.object({
43
48
  ...commonPropertyValues('last_edited_by'),
44
- last_edited_by: notionUserSchema,
49
+ last_edited_by: notionUserSchema
45
50
  });
46
51
  export const notionPagePropertyLastEditedTimeSchema = z.object({
47
52
  ...commonPropertyValues('last_edited_time'),
48
- last_edited_time: notionTimeFormat,
53
+ last_edited_time: notionTimeFormat
49
54
  });
50
55
  export const notionPagePropertyMultiSelectSchema = z.object({
51
56
  ...commonPropertyValues('multi_select'),
52
57
  multi_select: z.array(z.object({
53
58
  id: z.string(),
54
59
  name: z.string(),
55
- color: notionCommonColorEnum,
56
- })),
60
+ color: notionCommonColorEnum
61
+ }))
57
62
  });
58
63
  export const notionPagePropertyNumberSchema = z.object({
59
64
  ...commonPropertyValues('number'),
60
- number: z.number().nullable(),
65
+ number: z.number().nullable()
61
66
  });
62
67
  export const notionPagePropertyPeopleSchema = z.object({
63
68
  ...commonPropertyValues('people'),
64
- people: z.array(notionUserSchema),
69
+ people: z.array(notionUserSchema)
65
70
  });
66
71
  export const notionPagePropertyPhoneNumberSchema = z.object({
67
72
  ...commonPropertyValues('phone_number'),
68
- phone_number: z.string(),
73
+ phone_number: z.string()
69
74
  });
70
75
  export const notionPagePropertyRelationSchema = z.object({
71
76
  ...commonPropertyValues('relation'),
72
77
  relation: z.array(z.object({
73
- id: z.string(),
78
+ id: z.string()
74
79
  })),
75
- has_more: z.boolean(),
80
+ has_more: z.boolean()
76
81
  });
77
82
  export const notionPagePropertyRollupSchema = z.object({
78
83
  ...commonPropertyValues('rollup'),
@@ -106,76 +111,82 @@ export const notionPagePropertyRollupSchema = z.object({
106
111
  'show_unique',
107
112
  'sum',
108
113
  'unchecked',
109
- 'unique',
114
+ 'unique'
110
115
  ]),
111
- type: z.enum(['array', 'date', 'incomplete', 'number', 'unsupported']),
112
- }),
116
+ type: z.enum([
117
+ 'array',
118
+ 'date',
119
+ 'incomplete',
120
+ 'number',
121
+ 'unsupported'
122
+ ])
123
+ })
113
124
  });
114
125
  export const notionPagePropertyRichTextSchema = z.object({
115
126
  ...commonPropertyValues('rich_text'),
116
- rich_text: z.array(notionRichTextSchema),
127
+ rich_text: z.array(notionRichTextSchema)
117
128
  });
118
129
  export const notionPagePropertySelectSchema = z.object({
119
130
  ...commonPropertyValues('select'),
120
- select: z
121
- .object({
131
+ select: z.object({
122
132
  id: z.string(),
123
133
  name: z.string(),
124
- color: notionCommonColorEnum,
125
- })
126
- .nullable(),
134
+ color: notionCommonColorEnum
135
+ }).nullable()
127
136
  });
128
137
  export const notionPagePropertyStatusSchema = z.object({
129
138
  ...commonPropertyValues('status'),
130
139
  status: z.object({
131
140
  id: z.string(),
132
141
  name: z.string(),
133
- color: notionCommonColorEnum,
134
- }),
142
+ color: notionCommonColorEnum
143
+ })
135
144
  });
136
145
  export const notionPagePropertyTitleSchema = z.object({
137
146
  ...commonPropertyValues('title'),
138
- title: z.array(notionRichTextSchema),
147
+ title: z.array(notionRichTextSchema)
139
148
  });
140
149
  export const notionPagePropertyUrlSchema = z.object({
141
150
  ...commonPropertyValues('url'),
142
- url: z.string().url().nullable(),
151
+ url: z.string().url().nullable()
143
152
  });
144
153
  export const notionPagePropertyUniqueIdSchema = z.object({
145
154
  ...commonPropertyValues('unique_id'),
146
155
  unique_id: z.object({
147
156
  number: z.number(),
148
- prefix: z.string().nullable().optional(),
149
- }),
157
+ prefix: z.string().nullable().optional()
158
+ })
150
159
  });
151
160
  export const notionPagePropertyVerificationSchema = z.object({
152
161
  ...commonPropertyValues('verification'),
153
162
  verification: z.object({
154
- state: z.enum(['verified', 'unverified']),
163
+ state: z.enum([
164
+ 'verified',
165
+ 'unverified'
166
+ ]),
155
167
  verified_by: notionUserSchema.nullable(),
156
- date: notionDateSchema,
157
- }),
158
- });
159
- export const notionPageSchema = (properties) => z.object({
160
- object: z.literal('page'),
161
- id: z.string(),
162
- created_time: notionTimeFormat,
163
- created_by: notionPartialUserSchema,
164
- last_edited_time: notionTimeFormat,
165
- last_edited_by: notionPartialUserSchema,
166
- archived: z.boolean(),
167
- icon: notionFileSchema.or(notionEmojiSchema).nullable(),
168
- properties,
169
- parent: notionDatabaseParentSchema,
170
- url: z.string().url(),
171
- public_url: z.string().nullable(),
172
- });
173
- export const notionPagesSchema = (properties) => z.object({
174
- has_more: z.boolean(),
175
- next_cursor: z.string().nullable(),
176
- object: z.literal('list'),
177
- page_or_database: z.object({}),
178
- type: z.literal('page_or_database'),
179
- results: z.array(notionPageSchema(properties)),
180
- });
181
- //# sourceMappingURL=page.js.map
168
+ date: notionDateSchema
169
+ })
170
+ });
171
+ export const notionPageSchema = (properties)=>z.object({
172
+ object: z.literal('page'),
173
+ id: z.string(),
174
+ created_time: notionTimeFormat,
175
+ created_by: notionPartialUserSchema,
176
+ last_edited_time: notionTimeFormat,
177
+ last_edited_by: notionPartialUserSchema,
178
+ archived: z.boolean(),
179
+ icon: notionFileSchema.or(notionEmojiSchema).nullable(),
180
+ properties,
181
+ parent: notionDatabaseParentSchema,
182
+ url: z.string().url(),
183
+ public_url: z.string().nullable()
184
+ });
185
+ export const notionPagesSchema = (properties)=>z.object({
186
+ has_more: z.boolean(),
187
+ next_cursor: z.string().nullable(),
188
+ object: z.literal('list'),
189
+ page_or_database: z.object({}),
190
+ type: z.literal('page_or_database'),
191
+ results: z.array(notionPageSchema(properties))
192
+ });
@@ -1,18 +1,17 @@
1
1
  import { z } from 'zod';
2
2
  export const notionDatabaseParentSchema = z.object({
3
3
  type: z.literal('database_id'),
4
- database_id: z.string(),
4
+ database_id: z.string()
5
5
  });
6
6
  export const notionPageParentSchema = z.object({
7
7
  type: z.literal('page_id'),
8
- page_id: z.string(),
8
+ page_id: z.string()
9
9
  });
10
10
  export const notionWorkspaceParentSchema = z.object({
11
11
  type: z.literal('workspace'),
12
- workspace: z.literal(true),
12
+ workspace: z.literal(true)
13
13
  });
14
14
  export const notionBlockParentSchema = z.object({
15
15
  type: z.literal('block_id'),
16
- block_id: z.string(),
16
+ block_id: z.string()
17
17
  });
18
- //# sourceMappingURL=parent.js.map
@@ -1,31 +1,30 @@
1
1
  import { z } from 'zod';
2
2
  export const notionPartialUserSchema = z.object({
3
3
  object: z.literal('user'),
4
- user: z.string().optional(),
4
+ user: z.string().optional()
5
5
  });
6
6
  export const notionUserSchema = z.object({
7
7
  object: z.literal('user'),
8
8
  id: z.string(),
9
- type: z.enum(['person', 'bot']).optional(),
9
+ type: z.enum([
10
+ 'person',
11
+ 'bot'
12
+ ]).optional(),
10
13
  name: z.string().optional(),
11
14
  avatar_url: z.string().nullable().optional(),
12
15
  // type person
13
- person: z
14
- .object({
15
- email: z.string().email(),
16
- })
17
- .optional(),
16
+ person: z.object({
17
+ email: z.string().email()
18
+ }).optional(),
18
19
  // type bot
19
- bot: z
20
- .object({
21
- owner: z
22
- .object({
23
- type: z.enum(['workspace', 'user']),
24
- workspace: z.boolean(),
25
- })
26
- .optional(),
27
- workspace_name: z.string().optional(),
28
- })
29
- .optional(),
20
+ bot: z.object({
21
+ owner: z.object({
22
+ type: z.enum([
23
+ 'workspace',
24
+ 'user'
25
+ ]),
26
+ workspace: z.boolean()
27
+ }).optional(),
28
+ workspace_name: z.string().optional()
29
+ }).optional()
30
30
  });
31
- //# sourceMappingURL=user.js.map
@@ -1,10 +1,10 @@
1
1
  import { prisma } from '@driveflux/db';
2
2
  import { generateId } from '@driveflux/db/id';
3
- export const handleAgreeToTerms = async ({ agreedToTerms, subscribingUser, ipAddress, }) => {
3
+ export const handleAgreeToTerms = async ({ agreedToTerms, subscribingUser, ipAddress })=>{
4
4
  if (agreedToTerms && !subscribingUser.consented) {
5
5
  subscribingUser = await prisma.user.update({
6
6
  where: {
7
- id: subscribingUser.id,
7
+ id: subscribingUser.id
8
8
  },
9
9
  data: {
10
10
  consented: true,
@@ -13,12 +13,11 @@ export const handleAgreeToTerms = async ({ agreedToTerms, subscribingUser, ipAdd
13
13
  id: generateId('UserConsent'),
14
14
  ipAddress,
15
15
  consentType: 'terms',
16
- email: subscribingUser.email,
17
- },
18
- },
19
- },
16
+ email: subscribingUser.email
17
+ }
18
+ }
19
+ }
20
20
  });
21
21
  }
22
22
  return subscribingUser;
23
23
  };
24
- //# sourceMappingURL=agree.js.map
@@ -1,12 +1,12 @@
1
1
  import { buildOrDefineAbility } from '@driveflux/auth/authorization';
2
- import { makeProblem, PROBLEM_CONDITION_FAILED, PROBLEM_RESOURCE_BUSY, } from '@driveflux/problem';
2
+ import { makeProblem, PROBLEM_CONDITION_FAILED, PROBLEM_RESOURCE_BUSY } from '@driveflux/problem';
3
3
  import { Err, Ok } from '@driveflux/result';
4
- export const getUserAbility = async ({ requestUser, }) => {
4
+ export const getUserAbility = async ({ requestUser })=>{
5
5
  // Check if the user can reserve
6
6
  const requestUserAbility = await buildOrDefineAbility(requestUser);
7
7
  return requestUserAbility;
8
8
  };
9
- export const checkIfVehicleIsAvailableForReservation = async (vehicle, plan, allowDelisted) => {
9
+ export const checkIfVehicleIsAvailableForReservation = async (vehicle, plan, allowDelisted)=>{
10
10
  if (!vehicle.pricing) {
11
11
  return new Err(makeProblem(PROBLEM_RESOURCE_BUSY, 'This vehicle is not available for reservation'));
12
12
  }
@@ -22,4 +22,3 @@ export const checkIfVehicleIsAvailableForReservation = async (vehicle, plan, all
22
22
  }
23
23
  return new Ok(vehicle);
24
24
  };
25
- //# sourceMappingURL=checks.js.map
@@ -1,73 +1,75 @@
1
1
  import { config } from '@driveflux/config/backend';
2
- import { prisma, } from '@driveflux/db';
2
+ import { prisma } from '@driveflux/db';
3
3
  import { generateId } from '@driveflux/db/id';
4
4
  import { createPricingController } from '@driveflux/db/models/vehicle';
5
- import { getFluxExcessMileage, getFluxPiceMatrix, getHostExcessMileage, getHostsMatrix, getRecommendedMotorcycleDeposit, getStartFeeMatrix, } from '../vehicle/vehicle-pricing/index.js';
6
- export const fetchDisplayVehicle = async (displayVehicle) => {
7
- return typeof displayVehicle === 'string'
8
- ? await prisma.displayVehicle.findFirst({ where: { id: displayVehicle } })
9
- : displayVehicle;
5
+ import { getFluxExcessMileage, getFluxPiceMatrix, getHostExcessMileage, getHostsMatrix, getRecommendedMotorcycleDeposit, getStartFeeMatrix } from '../vehicle/vehicle-pricing/index.js';
6
+ export const fetchDisplayVehicle = async (displayVehicle)=>{
7
+ return typeof displayVehicle === 'string' ? await prisma.displayVehicle.findFirst({
8
+ where: {
9
+ id: displayVehicle
10
+ }
11
+ }) : displayVehicle;
10
12
  };
11
- export const createVehicleFromDisplayVehicle = async (displayVehicle, selectedColor) => {
13
+ export const createVehicleFromDisplayVehicle = async (displayVehicle, selectedColor)=>{
12
14
  const dv = await fetchDisplayVehicle(displayVehicle);
13
- if (!dv || typeof dv !== 'object')
14
- return;
15
- if (!dv.details)
16
- return;
17
- const mainImage = dv.images.main.find((m) => m.variant === selectedColor)?.url;
15
+ if (!dv || typeof dv !== 'object') return;
16
+ if (!dv.details) return;
17
+ const mainImage = dv.images.main.find((m)=>m.variant === selectedColor)?.url;
18
18
  const vehicleData = {
19
19
  id: generateId('Vehicle'),
20
20
  ...transformBasicVehicleData(dv),
21
21
  images: [
22
- ...(mainImage ? [transfromSingleImage(mainImage)] : []),
23
- ...transformImages(dv.images),
22
+ ...mainImage ? [
23
+ transfromSingleImage(mainImage)
24
+ ] : [],
25
+ ...transformImages(dv.images)
24
26
  ],
25
27
  ...transformBasePrices(dv.pricing),
26
28
  pricing: transformPriceMatrix(dv.type, dv.pricing),
27
29
  details: transformDetails(dv.details, selectedColor),
28
30
  host: {
29
31
  connect: {
30
- id: dv.defaultHostId,
31
- },
32
+ id: dv.defaultHostId
33
+ }
32
34
  },
33
35
  displayVehicle: {
34
36
  connect: {
35
- id: dv.id,
36
- },
37
- },
37
+ id: dv.id
38
+ }
39
+ }
38
40
  };
39
41
  return await prisma.vehicle.create({
40
42
  data: vehicleData,
41
43
  include: {
42
- host: true,
43
- },
44
+ host: true
45
+ }
44
46
  });
45
47
  };
46
- export const transfromVehicleDisplayToVehicle = async (displayVehicle, selectedColor) => {
48
+ export const transfromVehicleDisplayToVehicle = async (displayVehicle, selectedColor)=>{
47
49
  const dv = await fetchDisplayVehicle(displayVehicle);
48
- if (!dv || typeof dv !== 'object')
49
- return;
50
- if (!dv.details)
51
- return;
52
- const mainImage = dv.images.main.find((m) => m.variant === selectedColor)?.url;
50
+ if (!dv || typeof dv !== 'object') return;
51
+ if (!dv.details) return;
52
+ const mainImage = dv.images.main.find((m)=>m.variant === selectedColor)?.url;
53
53
  return {
54
54
  id: dv.id,
55
55
  ...transformBasicVehicleData(dv),
56
56
  images: [
57
- ...(mainImage ? [transfromSingleImage(mainImage)] : []),
58
- ...transformImages(dv.images),
57
+ ...mainImage ? [
58
+ transfromSingleImage(mainImage)
59
+ ] : [],
60
+ ...transformImages(dv.images)
59
61
  ],
60
62
  ...transformBasePrices(dv.pricing),
61
63
  pricing: transformPriceMatrix(dv.type, dv.pricing),
62
64
  details: transformDetails(dv.details, selectedColor),
63
65
  host: {
64
66
  address: {
65
- state: 'Kuala Lumpur',
66
- },
67
- },
67
+ state: 'Kuala Lumpur'
68
+ }
69
+ }
68
70
  };
69
71
  };
70
- export const transformBasicVehicleData = (dv) => {
72
+ export const transformBasicVehicleData = (dv)=>{
71
73
  return {
72
74
  registrationNumber: null,
73
75
  featured: false,
@@ -85,17 +87,17 @@ export const transformBasicVehicleData = (dv) => {
85
87
  type: dv.type,
86
88
  niceName: `${dv.make} ${dv.vehicleModel} ${dv.variant} ${dv.year}`,
87
89
  niceNameShort: `${dv.make} ${dv.vehicleModel}`,
88
- appliedCoupon: dv.appliedCoupon,
90
+ appliedCoupon: dv.appliedCoupon
89
91
  };
90
92
  };
91
- export const transformImages = (images) => {
93
+ export const transformImages = (images)=>{
92
94
  return [
93
95
  transfromSingleImage(images.exterior[0].url, 'exterior'),
94
96
  transfromSingleImage(images.interior[0].url, 'interior'),
95
- ...images.gallery.map((i) => transfromSingleImage(i.url)),
97
+ ...images.gallery.map((i)=>transfromSingleImage(i.url))
96
98
  ];
97
99
  };
98
- const transfromSingleImage = (imageUrl, inspectionType) => {
100
+ const transfromSingleImage = (imageUrl, inspectionType)=>{
99
101
  return {
100
102
  default: imageUrl,
101
103
  blurBase64: null,
@@ -106,20 +108,20 @@ const transfromSingleImage = (imageUrl, inspectionType) => {
106
108
  description: null,
107
109
  inspection: !!inspectionType,
108
110
  inspectionType: inspectionType || null,
109
- notActualPhoto: true,
111
+ notActualPhoto: true
110
112
  };
111
113
  };
112
- const transformBasePrices = (pricing) => {
114
+ const transformBasePrices = (pricing)=>{
113
115
  return {
114
116
  basePrice: pricing.matrix.plan36.lite,
115
117
  basePricePlan1: pricing.matrix.plan1.lite,
116
118
  basePricePlan12: pricing.matrix.plan12.lite,
117
119
  basePricePlan24: pricing.matrix.plan24.lite,
118
120
  basePricePlan36: pricing.matrix.plan36.lite,
119
- basePricePlan60: pricing.matrix.plan60.lite,
121
+ basePricePlan60: pricing.matrix.plan60.lite
120
122
  };
121
123
  };
122
- const transformPriceMatrix = (vehicleType, pricing) => {
124
+ const transformPriceMatrix = (vehicleType, pricing)=>{
123
125
  const baseline = pricing?.matrix.plan36.lite;
124
126
  const ultraTier = 'tier1';
125
127
  const fluxPriceCoefficient = 25;
@@ -132,16 +134,14 @@ const transformPriceMatrix = (vehicleType, pricing) => {
132
134
  const { availablePlans, availableMileagePackages } = getNonZeroKeys(priceMatrix);
133
135
  const pricingController = createPricingController({
134
136
  coefficient: fluxPriceCoefficient,
135
- vehicleType,
137
+ vehicleType
136
138
  });
137
139
  const startFeeMatrix = excludeServiceFeesFrom(getStartFeeMatrix(pricingController, baseline, flatPricing));
138
140
  const hostMatrix = excludeServiceFeesFrom(getHostsMatrix(pricingController, baseline, ultraTier, flatPricing));
139
141
  const hostExcessMileage = getHostExcessMileage(pricingController, baseline);
140
142
  const fluxPriceMatrix = excludeServiceFeesFrom(getFluxPiceMatrix(pricingController, vehicleType, baseline, hostMatrix, ultraTier, flatPricing));
141
143
  const fluxExcessMileage = getFluxExcessMileage(pricingController, baseline);
142
- const recommendedDeposit = pricing.refundableDeposit || vehicleType === 'motorcycle'
143
- ? getRecommendedMotorcycleDeposit(baseline)
144
- : null;
144
+ const recommendedDeposit = pricing.refundableDeposit || vehicleType === 'motorcycle' ? getRecommendedMotorcycleDeposit(baseline) : null;
145
145
  return {
146
146
  tmv,
147
147
  gfv,
@@ -160,31 +160,31 @@ const transformPriceMatrix = (vehicleType, pricing) => {
160
160
  excessMileage: fluxExcessMileage,
161
161
  originalExcessMileage: fluxExcessMileage,
162
162
  matrixComments: null,
163
- add: null,
163
+ add: null
164
164
  },
165
165
  hostTake: {
166
166
  matrix: hostMatrix,
167
167
  originalMatrix: hostMatrix,
168
168
  excessMileage: hostExcessMileage,
169
169
  originalExcessMileage: hostExcessMileage,
170
- matrixComments: null,
170
+ matrixComments: null
171
171
  },
172
172
  startFee: {
173
173
  matrix: startFeeMatrix,
174
174
  originalMatrix: startFeeMatrix,
175
- matrixComments: null,
176
- },
175
+ matrixComments: null
176
+ }
177
177
  };
178
178
  };
179
- const getNonZeroKeys = (matrix) => {
179
+ const getNonZeroKeys = (matrix)=>{
180
180
  const planKeys = new Set();
181
181
  const mileageKeys = new Set();
182
- for (const [plan, mileageMap] of Object.entries(matrix)) {
182
+ for (const [plan, mileageMap] of Object.entries(matrix)){
183
183
  const entries = Object.entries(mileageMap ?? {});
184
- const hasNonZero = entries.some(([_, value]) => (value ?? 0) > 0);
184
+ const hasNonZero = entries.some(([_, value])=>(value ?? 0) > 0);
185
185
  if (hasNonZero) {
186
186
  planKeys.add(plan);
187
- for (const [mileage, value] of entries) {
187
+ for (const [mileage, value] of entries){
188
188
  if ((value ?? 0) > 0) {
189
189
  mileageKeys.add(mileage);
190
190
  }
@@ -193,20 +193,20 @@ const getNonZeroKeys = (matrix) => {
193
193
  }
194
194
  return {
195
195
  availablePlans: Array.from(planKeys),
196
- availableMileagePackages: Array.from(mileageKeys),
196
+ availableMileagePackages: Array.from(mileageKeys)
197
197
  };
198
198
  };
199
- const _getInspection = () => {
199
+ const _getInspection = ()=>{
200
200
  return {
201
201
  exterior: 5,
202
202
  interior: 5,
203
203
  engine: 5,
204
204
  frame: 5,
205
205
  total: 5,
206
- comment: 'COMMENT HERE',
206
+ comment: 'COMMENT HERE'
207
207
  };
208
208
  };
209
- const transformDetails = (details, selectColor) => {
209
+ const transformDetails = (details, selectColor)=>{
210
210
  const color = selectColor || details.colors[0].name || '';
211
211
  return {
212
212
  numberOfSeats: details.numberOfSeats,
@@ -214,31 +214,25 @@ const transformDetails = (details, selectColor) => {
214
214
  bodyType: details.bodyType,
215
215
  transmission: details.transmission,
216
216
  engineType: details.fuelType,
217
- engineCapacity: details.fuelType === 'electric'
218
- ? details.batteryCapacity
219
- : details.engineCapacity,
217
+ engineCapacity: details.fuelType === 'electric' ? details.batteryCapacity : details.engineCapacity,
220
218
  drivetrain: details.drivetrain,
221
219
  accelerationTo100km: details.accelerationTo100km,
222
220
  fuelConsumptionLitersPer100Km: details.fuelConsumptionLitersPer100Km,
223
221
  color,
224
222
  features: details.features,
225
- condition: 'new',
223
+ condition: 'new'
226
224
  };
227
225
  };
228
- const excludeServiceFeesFrom = (originalMatrix) => {
226
+ const excludeServiceFeesFrom = (originalMatrix)=>{
229
227
  const matrix = {};
230
- for (const [planKey, planValue] of Object.entries(originalMatrix)) {
231
- if (!planValue)
232
- continue;
233
- if (!matrix[planKey])
234
- matrix[planKey] = {};
235
- for (const [mileageKey, price] of Object.entries(planValue)) {
228
+ for (const [planKey, planValue] of Object.entries(originalMatrix)){
229
+ if (!planValue) continue;
230
+ if (!matrix[planKey]) matrix[planKey] = {};
231
+ for (const [mileageKey, price] of Object.entries(planValue)){
236
232
  if (typeof price === 'number') {
237
- matrix[planKey][mileageKey] =
238
- price / (1 + config.taxRate);
233
+ matrix[planKey][mileageKey] = price / (1 + config.taxRate);
239
234
  }
240
235
  }
241
236
  }
242
237
  return matrix;
243
238
  };
244
- //# sourceMappingURL=display-vehicle.js.map