@nuwah/vertical-sdk 0.0.0-stage → 0.2.0-rc.1
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.
- package/LICENSE +17 -0
- package/README.md +229 -2
- package/bin/nuwah-contract-check-rules.d.mts +41 -0
- package/bin/nuwah-contract-check-rules.mjs +333 -0
- package/bin/nuwah-contract-check.mjs +64 -0
- package/dist/accounting.d.ts +1417 -0
- package/dist/accounting.js +274 -0
- package/dist/active-org.d.ts +13 -0
- package/dist/active-org.js +59 -0
- package/dist/actors.d.ts +448 -0
- package/dist/actors.js +143 -0
- package/dist/ai.d.ts +359 -0
- package/dist/ai.js +229 -0
- package/dist/analytics.d.ts +37 -0
- package/dist/analytics.js +8 -0
- package/dist/atlas.d.ts +291 -0
- package/dist/atlas.js +78 -0
- package/dist/audit.d.ts +193 -0
- package/dist/audit.js +26 -0
- package/dist/authentication.d.ts +119 -0
- package/dist/authentication.js +83 -0
- package/dist/awards.d.ts +38 -0
- package/dist/awards.js +10 -0
- package/dist/blueprint/document.d.ts +178 -0
- package/dist/blueprint/document.js +17 -0
- package/dist/blueprint/index.d.ts +3 -0
- package/dist/blueprint/index.js +5 -0
- package/dist/blueprint/manifest.d.ts +105 -0
- package/dist/blueprint/manifest.js +11 -0
- package/dist/blueprint/validate.d.ts +14 -0
- package/dist/blueprint/validate.js +416 -0
- package/dist/bookings-directory.d.ts +118 -0
- package/dist/bookings-directory.js +289 -0
- package/dist/bookings-extra.d.ts +1448 -0
- package/dist/bookings-extra.js +582 -0
- package/dist/bookings.d.ts +1365 -0
- package/dist/bookings.js +305 -0
- package/dist/builder-code.d.ts +164 -0
- package/dist/builder-code.js +12 -0
- package/dist/builder-core-gaps.d.ts +83 -0
- package/dist/builder-core-gaps.js +8 -0
- package/dist/builder-repos.d.ts +73 -0
- package/dist/builder-repos.js +37 -0
- package/dist/builder.d.ts +730 -0
- package/dist/builder.js +105 -0
- package/dist/campaigns.d.ts +105 -0
- package/dist/campaigns.js +25 -0
- package/dist/catalogs.d.ts +188 -0
- package/dist/catalogs.js +36 -0
- package/dist/commerce-ai.d.ts +182 -0
- package/dist/commerce-ai.js +27 -0
- package/dist/connections.d.ts +278 -0
- package/dist/connections.js +96 -0
- package/dist/content-control.d.ts +121 -0
- package/dist/content-control.js +23 -0
- package/dist/contributions.d.ts +560 -0
- package/dist/contributions.js +140 -0
- package/dist/conversation-assist.d.ts +154 -0
- package/dist/conversation-assist.js +51 -0
- package/dist/conversation-info.d.ts +219 -0
- package/dist/conversation-info.js +43 -0
- package/dist/crm.d.ts +533 -0
- package/dist/crm.js +142 -0
- package/dist/dashboards.d.ts +119 -0
- package/dist/dashboards.js +22 -0
- package/dist/delegations.d.ts +161 -0
- package/dist/delegations.js +39 -0
- package/dist/docs.d.ts +289 -0
- package/dist/docs.js +49 -0
- package/dist/documents.d.ts +317 -0
- package/dist/documents.js +84 -0
- package/dist/drafts.d.ts +132 -0
- package/dist/drafts.js +56 -0
- package/dist/engagements.d.ts +133 -0
- package/dist/engagements.js +15 -0
- package/dist/event-stream.d.ts +54 -0
- package/dist/event-stream.js +228 -0
- package/dist/exchanges.d.ts +447 -0
- package/dist/exchanges.js +145 -0
- package/dist/exports.d.ts +113 -0
- package/dist/exports.js +81 -0
- package/dist/feeds.d.ts +228 -0
- package/dist/feeds.js +52 -0
- package/dist/files.d.ts +56 -0
- package/dist/files.js +55 -0
- package/dist/finance-insights.d.ts +41 -0
- package/dist/finance-insights.js +61 -0
- package/dist/fixed-assets.d.ts +155 -0
- package/dist/fixed-assets.js +28 -0
- package/dist/fulfilment-jobs.d.ts +405 -0
- package/dist/fulfilment-jobs.js +76 -0
- package/dist/fulfilment.d.ts +205 -0
- package/dist/fulfilment.js +39 -0
- package/dist/hr.d.ts +350 -0
- package/dist/hr.js +94 -0
- package/dist/http.d.ts +124 -0
- package/dist/http.js +392 -0
- package/dist/inbox.d.ts +206 -0
- package/dist/inbox.js +36 -0
- package/dist/index.d.ts +384 -0
- package/dist/index.js +294 -0
- package/dist/insights.d.ts +176 -0
- package/dist/insights.js +52 -0
- package/dist/inventory.d.ts +797 -0
- package/dist/inventory.js +120 -0
- package/dist/list-query.d.ts +211 -0
- package/dist/list-query.js +158 -0
- package/dist/listings.d.ts +381 -0
- package/dist/listings.js +173 -0
- package/dist/location-sharing.d.ts +83 -0
- package/dist/location-sharing.js +20 -0
- package/dist/marketplace.d.ts +268 -0
- package/dist/marketplace.js +59 -0
- package/dist/matching.d.ts +103 -0
- package/dist/matching.js +22 -0
- package/dist/media.d.ts +221 -0
- package/dist/media.js +239 -0
- package/dist/metrics.d.ts +125 -0
- package/dist/metrics.js +45 -0
- package/dist/moderation.d.ts +240 -0
- package/dist/moderation.js +40 -0
- package/dist/money.d.ts +41 -0
- package/dist/money.js +79 -0
- package/dist/my-data.d.ts +266 -0
- package/dist/my-data.js +32 -0
- package/dist/names.d.ts +14 -0
- package/dist/names.js +17 -0
- package/dist/occasions.d.ts +256 -0
- package/dist/occasions.js +40 -0
- package/dist/onboarding.d.ts +88 -0
- package/dist/onboarding.js +38 -0
- package/dist/pagination.d.ts +204 -0
- package/dist/pagination.js +141 -0
- package/dist/party-baseline-attributes.d.ts +245 -0
- package/dist/party-baseline-attributes.js +36 -0
- package/dist/party.d.ts +401 -0
- package/dist/party.js +56 -0
- package/dist/patient.d.ts +161 -0
- package/dist/patient.js +45 -0
- package/dist/payroll.d.ts +378 -0
- package/dist/payroll.js +60 -0
- package/dist/person-addresses.d.ts +88 -0
- package/dist/person-addresses.js +18 -0
- package/dist/person-cart.d.ts +250 -0
- package/dist/person-cart.js +63 -0
- package/dist/person-chat-assist.d.ts +47 -0
- package/dist/person-chat-assist.js +13 -0
- package/dist/person-data-webhooks.d.ts +72 -0
- package/dist/person-data-webhooks.js +86 -0
- package/dist/person-data.d.ts +212 -0
- package/dist/person-data.js +162 -0
- package/dist/person-locations.d.ts +54 -0
- package/dist/person-locations.js +6 -0
- package/dist/person-messaging.d.ts +405 -0
- package/dist/person-messaging.js +112 -0
- package/dist/person-notifications.d.ts +319 -0
- package/dist/person-notifications.js +164 -0
- package/dist/personalisation.d.ts +21 -0
- package/dist/personalisation.js +8 -0
- package/dist/platform.d.ts +63 -0
- package/dist/platform.js +45 -0
- package/dist/portfolio.d.ts +163 -0
- package/dist/portfolio.js +28 -0
- package/dist/pos.d.ts +743 -0
- package/dist/pos.js +129 -0
- package/dist/procurement.d.ts +664 -0
- package/dist/procurement.js +157 -0
- package/dist/promotions.d.ts +169 -0
- package/dist/promotions.js +39 -0
- package/dist/publications.d.ts +583 -0
- package/dist/publications.js +164 -0
- package/dist/ranking.d.ts +43 -0
- package/dist/ranking.js +34 -0
- package/dist/ratings.d.ts +293 -0
- package/dist/ratings.js +109 -0
- package/dist/reactions.d.ts +123 -0
- package/dist/reactions.js +41 -0
- package/dist/recipient-orders.d.ts +294 -0
- package/dist/recipient-orders.js +73 -0
- package/dist/relationships.d.ts +18 -0
- package/dist/relationships.js +8 -0
- package/dist/reporting.d.ts +107 -0
- package/dist/reporting.js +56 -0
- package/dist/sales.d.ts +270 -0
- package/dist/sales.js +66 -0
- package/dist/shares.d.ts +105 -0
- package/dist/shares.js +27 -0
- package/dist/shop.d.ts +993 -0
- package/dist/shop.js +215 -0
- package/dist/shopping-assistant.d.ts +65 -0
- package/dist/shopping-assistant.js +14 -0
- package/dist/spaces.d.ts +422 -0
- package/dist/spaces.js +118 -0
- package/dist/stored-value.d.ts +754 -0
- package/dist/stored-value.js +177 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +2 -0
- package/dist/vault.d.ts +290 -0
- package/dist/vault.js +55 -0
- package/dist/vertical-runtime.d.ts +17 -0
- package/dist/vertical-runtime.js +8 -0
- package/dist/vite/build-manifest-plugin.d.ts +42 -0
- package/dist/vite/build-manifest-plugin.js +42 -0
- package/dist/vite/first-paint-plugin.d.ts +26 -0
- package/dist/vite/first-paint-plugin.js +57 -0
- package/dist/wishlists.d.ts +591 -0
- package/dist/wishlists.js +188 -0
- package/dist/workbench.d.ts +114 -0
- package/dist/workbench.js +22 -0
- package/dist/workspace.d.ts +190 -0
- package/dist/workspace.js +41 -0
- package/package.json +52 -4
- package/templates/extension-image.Dockerfile +38 -0
- package/templates/nuwah-vertical.yml +102 -0
- package/templates/vertical-app/.env.example +34 -0
- package/templates/vertical-app/README.md +108 -0
- package/templates/vertical-app/github/workflows/ci.yml +51 -0
- package/templates/vertical-app/gitignore +5 -0
- package/templates/vertical-app/index.html +12 -0
- package/templates/vertical-app/package.json +28 -0
- package/templates/vertical-app/src/App.tsx +64 -0
- package/templates/vertical-app/src/blueprint/blueprint.ts +45 -0
- package/templates/vertical-app/src/blueprint/screens.ts +15 -0
- package/templates/vertical-app/src/env.d.ts +18 -0
- package/templates/vertical-app/src/index.css +139 -0
- package/templates/vertical-app/src/lib/i18n.ts +5 -0
- package/templates/vertical-app/src/lib/iam.ts +19 -0
- package/templates/vertical-app/src/lib/operations.ts +93 -0
- package/templates/vertical-app/src/lib/router.ts +24 -0
- package/templates/vertical-app/src/lib/sdk.ts +21 -0
- package/templates/vertical-app/src/lib/theme.ts +18 -0
- package/templates/vertical-app/src/lib/words.ts +39 -0
- package/templates/vertical-app/src/main.tsx +25 -0
- package/templates/vertical-app/src/pages/AppScreens.tsx +71 -0
- package/templates/vertical-app/src/pages/AuthCallback.tsx +44 -0
- package/templates/vertical-app/src/pages/Home.tsx +36 -0
- package/templates/vertical-app/tsconfig.json +24 -0
- package/templates/vertical-app/vite.config.ts +23 -0
- package/templates/vertical-ci.yml +192 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { NuwahApiError } from './http.js';
|
|
2
|
+
import { createPartyNamespace } from './party.js';
|
|
3
|
+
const CLIENT_ROLE = 'client';
|
|
4
|
+
const PRACTITIONER_ROLE = 'practitioner';
|
|
5
|
+
|
|
6
|
+
function activeSpan(party, role) {
|
|
7
|
+
return party.roles?.find((entry) => entry.role === role && entry.active) ?? null;
|
|
8
|
+
}
|
|
9
|
+
function stringOrNull(value) {
|
|
10
|
+
return typeof value === 'string' && value !== '' ? value : null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function shimInstant(value) {
|
|
14
|
+
if (value === null || value === undefined || value === '') {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const instant = new Date(value);
|
|
18
|
+
if (Number.isNaN(instant.getTime())) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
return instant.toISOString().replace(/\.(\d{3})Z$/, '.$1000Z');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function shimCalendarDate(value) {
|
|
25
|
+
const date = stringOrNull(value);
|
|
26
|
+
if (date === null) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const calendarDay = /^(\d{4}-\d{2}-\d{2})/.exec(date);
|
|
30
|
+
return calendarDay ? `${calendarDay[1]}T00:00:00.000000Z` : date;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function calendarDayForWrite(value) {
|
|
34
|
+
if (value === null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const calendarDay = /^(\d{4}-\d{2}-\d{2})/.exec(value);
|
|
38
|
+
return calendarDay ? calendarDay[1] : value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function bookingClientFromParty(party) {
|
|
42
|
+
const clientSpan = activeSpan(party, CLIENT_ROLE);
|
|
43
|
+
const roleAttributes = clientSpan?.attributes ?? {};
|
|
44
|
+
const defaultDuration = roleAttributes['default_duration_minutes'];
|
|
45
|
+
return {
|
|
46
|
+
id: party.id,
|
|
47
|
+
platform_person_id: party.platform_person_id,
|
|
48
|
+
last_booked_at: stringOrNull(roleAttributes['last_booked_at']),
|
|
49
|
+
display_name: party.display_name,
|
|
50
|
+
email: party.email,
|
|
51
|
+
phone: party.phone,
|
|
52
|
+
date_of_birth: shimCalendarDate(party.attributes['date_of_birth']),
|
|
53
|
+
gender: stringOrNull(party.attributes['gender']),
|
|
54
|
+
default_duration_minutes: typeof defaultDuration === 'number' ? defaultDuration : null,
|
|
55
|
+
status: party.status,
|
|
56
|
+
notes: stringOrNull(roleAttributes['notes']),
|
|
57
|
+
created_at: shimInstant(party.created_at),
|
|
58
|
+
updated_at: shimInstant(party.updated_at),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function bookingPractitionerFromParty(party) {
|
|
63
|
+
const practitionerSpan = activeSpan(party, PRACTITIONER_ROLE);
|
|
64
|
+
const roleAttributes = practitionerSpan?.attributes ?? {};
|
|
65
|
+
return {
|
|
66
|
+
id: party.id,
|
|
67
|
+
platform_person_id: party.platform_person_id,
|
|
68
|
+
display_name: party.display_name,
|
|
69
|
+
email: party.email,
|
|
70
|
+
phone: party.phone,
|
|
71
|
+
specialty: stringOrNull(roleAttributes['specialty']),
|
|
72
|
+
employment_type: stringOrNull(roleAttributes['employment_type']),
|
|
73
|
+
|
|
74
|
+
is_senior: roleAttributes['is_senior'] === true,
|
|
75
|
+
status: party.status,
|
|
76
|
+
notes: stringOrNull(roleAttributes['notes']),
|
|
77
|
+
created_at: shimInstant(party.created_at),
|
|
78
|
+
updated_at: shimInstant(party.updated_at),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function present(input, keys) {
|
|
83
|
+
const picked = {};
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
if (input[key] !== undefined) {
|
|
86
|
+
picked[key] = input[key];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return picked;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function presentAndSet(input, keys) {
|
|
93
|
+
const picked = {};
|
|
94
|
+
for (const key of keys) {
|
|
95
|
+
if (input[key] !== undefined && input[key] !== null) {
|
|
96
|
+
picked[key] = input[key];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return picked;
|
|
100
|
+
}
|
|
101
|
+
function hasKeys(value) {
|
|
102
|
+
return Object.keys(value).length > 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function shimErrorKey(directoryPath) {
|
|
106
|
+
const roleField = /^role_attributes\.[^.]+\.(.+)$/.exec(directoryPath);
|
|
107
|
+
if (roleField) {
|
|
108
|
+
return roleField[1] === '*' ? 'role' : roleField[1];
|
|
109
|
+
}
|
|
110
|
+
const partyField = /^attributes\.(.+)$/.exec(directoryPath);
|
|
111
|
+
return partyField ? partyField[1] : directoryPath;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function shimErrorsFromDirectory(body) {
|
|
115
|
+
if (!body || typeof body !== 'object' || !('errors' in body)) {
|
|
116
|
+
return body;
|
|
117
|
+
}
|
|
118
|
+
const original = body.errors;
|
|
119
|
+
if (!original || typeof original !== 'object') {
|
|
120
|
+
return body;
|
|
121
|
+
}
|
|
122
|
+
const errors = {};
|
|
123
|
+
const bilingual = {};
|
|
124
|
+
for (const [path, value] of Object.entries(original)) {
|
|
125
|
+
const key = shimErrorKey(path);
|
|
126
|
+
const messages = Array.isArray(value)
|
|
127
|
+
? value.map((message) => ({ en: String(message), ar: String(message) }))
|
|
128
|
+
: value && typeof value === 'object' && 'en' in value
|
|
129
|
+
? [{ en: String(value.en), ar: String(value.ar ?? value.en) }]
|
|
130
|
+
: [{ en: String(value), ar: String(value) }];
|
|
131
|
+
errors[key] = [...(errors[key] ?? []), ...messages.map((message) => message.en)];
|
|
132
|
+
for (const message of messages) {
|
|
133
|
+
const existing = bilingual[key];
|
|
134
|
+
bilingual[key] = existing === undefined
|
|
135
|
+
? message
|
|
136
|
+
: { en: `${existing.en} ${message.en}`, ar: `${existing.ar} ${message.ar}` };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const translated = {
|
|
140
|
+
...body,
|
|
141
|
+
errors,
|
|
142
|
+
errors_bilingual: bilingual,
|
|
143
|
+
directory_errors: original,
|
|
144
|
+
};
|
|
145
|
+
return translated;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function withShimErrors(write) {
|
|
149
|
+
try {
|
|
150
|
+
return await write();
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
if (error instanceof NuwahApiError && error.status === 422) {
|
|
154
|
+
throw new NuwahApiError(422, shimErrorsFromDirectory(error.body), error.message, error.traceId);
|
|
155
|
+
}
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function notHoldingRole(partyId, role) {
|
|
161
|
+
return new NuwahApiError(404, { message: `Party ${partyId} does not hold the ${role} role.` });
|
|
162
|
+
}
|
|
163
|
+
export function createBookingsDirectoryNamespace(http) {
|
|
164
|
+
const party = createPartyNamespace(http);
|
|
165
|
+
|
|
166
|
+
async function partyHolding(partyId, role) {
|
|
167
|
+
const resolved = await party.get(partyId);
|
|
168
|
+
if (activeSpan(resolved.data, role) === null) {
|
|
169
|
+
throw notHoldingRole(partyId, role);
|
|
170
|
+
}
|
|
171
|
+
return resolved.data;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function page(role, query, present) {
|
|
175
|
+
const collection = await party.list({
|
|
176
|
+
role,
|
|
177
|
+
...(query.search ? { q: query.search } : {}),
|
|
178
|
+
...(query.status ? { status: query.status } : {}),
|
|
179
|
+
...(query.role_state ? { role_state: query.role_state } : {}),
|
|
180
|
+
...(query.page === undefined ? {} : { page: query.page }),
|
|
181
|
+
...(query.per_page === undefined ? {} : { per_page: query.per_page }),
|
|
182
|
+
});
|
|
183
|
+
return {
|
|
184
|
+
data: collection.data.map(present),
|
|
185
|
+
meta: {
|
|
186
|
+
current_page: collection.meta.current_page,
|
|
187
|
+
last_page: collection.meta.last_page,
|
|
188
|
+
per_page: collection.meta.per_page,
|
|
189
|
+
total: collection.meta.total,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function writeBothHalves(current, role, partyChange, roleChange) {
|
|
195
|
+
const partyId = current.id;
|
|
196
|
+
|
|
197
|
+
const withheldOnParty = current.attributes_withheld ?? [];
|
|
198
|
+
const withheldOnRole = activeSpan(current, role)?.attributes_withheld ?? [];
|
|
199
|
+
const partyAttributes = partyChange['attributes'];
|
|
200
|
+
if (partyAttributes !== undefined) {
|
|
201
|
+
for (const key of withheldOnParty)
|
|
202
|
+
delete partyAttributes[key];
|
|
203
|
+
if (!hasKeys(partyAttributes))
|
|
204
|
+
delete partyChange['attributes'];
|
|
205
|
+
}
|
|
206
|
+
for (const key of withheldOnRole)
|
|
207
|
+
delete roleChange[key];
|
|
208
|
+
if (!hasKeys(partyChange) && !hasKeys(roleChange)) {
|
|
209
|
+
return (await party.get(partyId)).data;
|
|
210
|
+
}
|
|
211
|
+
return (await withShimErrors(() => party.update(partyId, {
|
|
212
|
+
...partyChange,
|
|
213
|
+
...(hasKeys(roleChange) ? { role_attributes: { [role]: roleChange } } : {}),
|
|
214
|
+
}))).data;
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
clients: {
|
|
218
|
+
|
|
219
|
+
list: (query = {}) => page(CLIENT_ROLE, query, bookingClientFromParty),
|
|
220
|
+
|
|
221
|
+
get: async (partyId) => bookingClientFromParty(await partyHolding(partyId, CLIENT_ROLE)),
|
|
222
|
+
|
|
223
|
+
create: async (input) => {
|
|
224
|
+
const attributes = {};
|
|
225
|
+
if (input.date_of_birth !== undefined && input.date_of_birth !== null)
|
|
226
|
+
attributes.date_of_birth = calendarDayForWrite(input.date_of_birth);
|
|
227
|
+
if (input.gender !== undefined && input.gender !== null)
|
|
228
|
+
attributes.gender = input.gender;
|
|
229
|
+
const roleAttributes = presentAndSet(input, ['notes', 'default_duration_minutes']);
|
|
230
|
+
const created = await withShimErrors(() => party.create({
|
|
231
|
+
display_name: input.display_name,
|
|
232
|
+
party_type: 'person',
|
|
233
|
+
...presentAndSet(input, ['email', 'phone', 'platform_person_id']),
|
|
234
|
+
role: CLIENT_ROLE,
|
|
235
|
+
...(hasKeys(attributes) ? { attributes } : {}),
|
|
236
|
+
...(hasKeys(roleAttributes) ? { role_attributes: { [CLIENT_ROLE]: roleAttributes } } : {}),
|
|
237
|
+
}));
|
|
238
|
+
return bookingClientFromParty(created.data);
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
update: async (partyId, input) => {
|
|
242
|
+
const current = await partyHolding(partyId, CLIENT_ROLE);
|
|
243
|
+
const attributes = {};
|
|
244
|
+
if (input.date_of_birth !== undefined)
|
|
245
|
+
attributes.date_of_birth = calendarDayForWrite(input.date_of_birth);
|
|
246
|
+
if (input.gender !== undefined)
|
|
247
|
+
attributes.gender = input.gender;
|
|
248
|
+
const partyChange = {
|
|
249
|
+
...present(input, ['display_name', 'email', 'phone', 'status']),
|
|
250
|
+
...(hasKeys(attributes) ? { attributes } : {}),
|
|
251
|
+
};
|
|
252
|
+
const roleChange = present(input, ['notes', 'default_duration_minutes']);
|
|
253
|
+
return bookingClientFromParty(await writeBothHalves(current, CLIENT_ROLE, partyChange, roleChange));
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
practitioners: {
|
|
257
|
+
|
|
258
|
+
list: (query = {}) => page(PRACTITIONER_ROLE, query, bookingPractitionerFromParty),
|
|
259
|
+
|
|
260
|
+
create: async (input) => {
|
|
261
|
+
const roleAttributes = presentAndSet(input, ['specialty', 'employment_type', 'notes']);
|
|
262
|
+
|
|
263
|
+
if (input.is_senior === true) {
|
|
264
|
+
roleAttributes.is_senior = true;
|
|
265
|
+
}
|
|
266
|
+
const created = await withShimErrors(() => party.create({
|
|
267
|
+
display_name: input.display_name,
|
|
268
|
+
party_type: 'person',
|
|
269
|
+
...presentAndSet(input, ['email', 'phone', 'platform_person_id']),
|
|
270
|
+
role: PRACTITIONER_ROLE,
|
|
271
|
+
...(hasKeys(roleAttributes) ? { role_attributes: { [PRACTITIONER_ROLE]: roleAttributes } } : {}),
|
|
272
|
+
}));
|
|
273
|
+
return bookingPractitionerFromParty(created.data);
|
|
274
|
+
},
|
|
275
|
+
|
|
276
|
+
get: async (partyId) => bookingPractitionerFromParty(await partyHolding(partyId, PRACTITIONER_ROLE)),
|
|
277
|
+
|
|
278
|
+
update: async (partyId, input) => {
|
|
279
|
+
const current = await partyHolding(partyId, PRACTITIONER_ROLE);
|
|
280
|
+
const partyChange = present(input, ['display_name', 'email', 'phone', 'status']);
|
|
281
|
+
const roleChange = present(input, ['specialty', 'employment_type', 'notes']);
|
|
282
|
+
if (input.is_senior !== undefined) {
|
|
283
|
+
roleChange.is_senior = input.is_senior ? true : null;
|
|
284
|
+
}
|
|
285
|
+
return bookingPractitionerFromParty(await writeBothHalves(current, PRACTITIONER_ROLE, partyChange, roleChange));
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
}
|