gymmonk-schema 0.34.0 → 0.36.0
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/dist/add-person-form.d.ts +67 -62
- package/dist/add-person-form.d.ts.map +1 -1
- package/dist/add-person-form.js +93 -44
- package/dist/add-person-form.js.map +1 -1
- package/dist/center.d.ts +1 -1
- package/dist/center.d.ts.map +1 -1
- package/dist/center.js.map +1 -1
- package/dist/enrolment.js.map +1 -1
- package/dist/member.js.map +1 -1
- package/package.json +1 -1
|
@@ -32,6 +32,22 @@ import { staffRoleSchema } from './staff.js';
|
|
|
32
32
|
*/
|
|
33
33
|
export declare const ADD_PERSON_MIN_AGE_YEARS = 5;
|
|
34
34
|
export declare const ADD_PERSON_MAX_AGE_YEARS = 100;
|
|
35
|
+
/**
|
|
36
|
+
* The three cells joined into the `YYYY-MM-DD` the API stores, or `undefined`
|
|
37
|
+
* when nothing was entered.
|
|
38
|
+
*
|
|
39
|
+
* Desk entry does not require a date of birth — a gym adds people with
|
|
40
|
+
* whatever it has to hand — so "blank" is a real answer and has to survive the
|
|
41
|
+
* whole way to the body as an ABSENT field rather than an empty string the
|
|
42
|
+
* API would reject.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isoFromDobCells(day: string, month: string, year: string): string | undefined;
|
|
45
|
+
/** A stored `YYYY-MM-DD` split back into the cells, for seeding an edit form. */
|
|
46
|
+
export declare function dobCellsFromIso(iso: string | null | undefined): {
|
|
47
|
+
dobDay: string;
|
|
48
|
+
dobMonth: string;
|
|
49
|
+
dobYear: string;
|
|
50
|
+
};
|
|
35
51
|
/**
|
|
36
52
|
* One emergency-contact row: WHO to call, on what number, and how they are
|
|
37
53
|
* related. A row is either wholly blank (ignored) or names a person.
|
|
@@ -65,49 +81,14 @@ export declare const addMemberFormSchema: z.ZodObject<{
|
|
|
65
81
|
name: z.ZodString;
|
|
66
82
|
email: z.ZodEmail;
|
|
67
83
|
phone: z.ZodString;
|
|
68
|
-
|
|
84
|
+
dobDay: z.ZodString;
|
|
85
|
+
dobMonth: z.ZodString;
|
|
86
|
+
dobYear: z.ZodString;
|
|
69
87
|
gender: z.ZodNullable<z.ZodEnum<{
|
|
70
88
|
male: "male";
|
|
71
89
|
female: "female";
|
|
72
90
|
other: "other";
|
|
73
91
|
}>> & z.ZodType<{} | undefined, "male" | "female" | "other" | null, z.core.$ZodTypeInternals<{} | undefined, "male" | "female" | "other" | null>>;
|
|
74
|
-
address: z.ZodNullable<z.ZodObject<{
|
|
75
|
-
country: z.ZodObject<{
|
|
76
|
-
id: z.ZodString;
|
|
77
|
-
name: z.ZodString;
|
|
78
|
-
}, z.core.$strip>;
|
|
79
|
-
state: z.ZodObject<{
|
|
80
|
-
id: z.ZodString;
|
|
81
|
-
name: z.ZodString;
|
|
82
|
-
}, z.core.$strip>;
|
|
83
|
-
district: z.ZodOptional<z.ZodObject<{
|
|
84
|
-
id: z.ZodString;
|
|
85
|
-
name: z.ZodString;
|
|
86
|
-
}, z.core.$strip>>;
|
|
87
|
-
locality: z.ZodOptional<z.ZodObject<{
|
|
88
|
-
id: z.ZodString;
|
|
89
|
-
name: z.ZodString;
|
|
90
|
-
type: z.ZodEnum<{
|
|
91
|
-
SUB_DISTRICT: "SUB_DISTRICT";
|
|
92
|
-
BLOCK: "BLOCK";
|
|
93
|
-
GRAM_PANCHAYAT: "GRAM_PANCHAYAT";
|
|
94
|
-
VILLAGE: "VILLAGE";
|
|
95
|
-
HAMLET: "HAMLET";
|
|
96
|
-
URBAN_BODY: "URBAN_BODY";
|
|
97
|
-
URBAN_WARD: "URBAN_WARD";
|
|
98
|
-
LOCALITY: "LOCALITY";
|
|
99
|
-
}>;
|
|
100
|
-
}, z.core.$strip>>;
|
|
101
|
-
line1: z.ZodString;
|
|
102
|
-
landmark: z.ZodPreprocess<z.ZodOptional<z.ZodString>>;
|
|
103
|
-
pincode: z.ZodString;
|
|
104
|
-
ancestry: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
105
|
-
coords: z.ZodOptional<z.ZodObject<{
|
|
106
|
-
lat: z.ZodNumber;
|
|
107
|
-
lng: z.ZodNumber;
|
|
108
|
-
source: z.ZodString;
|
|
109
|
-
}, z.core.$strip>>;
|
|
110
|
-
}, z.core.$strip>>;
|
|
111
92
|
bloodGroup: z.ZodUnion<[z.ZodEnum<{
|
|
112
93
|
"A+": "A+";
|
|
113
94
|
"A-": "A-";
|
|
@@ -118,7 +99,6 @@ export declare const addMemberFormSchema: z.ZodObject<{
|
|
|
118
99
|
"AB+": "AB+";
|
|
119
100
|
"AB-": "AB-";
|
|
120
101
|
}>, z.ZodLiteral<"">]>;
|
|
121
|
-
idProofUrl: z.ZodString;
|
|
122
102
|
avatarUrl: z.ZodString;
|
|
123
103
|
contacts: z.ZodArray<z.ZodObject<{
|
|
124
104
|
name: z.ZodString;
|
|
@@ -126,19 +106,38 @@ export declare const addMemberFormSchema: z.ZodObject<{
|
|
|
126
106
|
phone: z.ZodString;
|
|
127
107
|
}, z.core.$strip>>;
|
|
128
108
|
}, z.core.$strip>;
|
|
109
|
+
/**
|
|
110
|
+
* Adding a member asks for the person, not their paperwork.
|
|
111
|
+
*
|
|
112
|
+
* No address and no ID proof: neither is something a front desk has when
|
|
113
|
+
* somebody walks in, both were optional and therefore skipped, and the member's
|
|
114
|
+
* own screens never collected them either. They live on the EDIT form, where an
|
|
115
|
+
* owner fills them in once they actually have them, and on the staff form,
|
|
116
|
+
* where an employer legitimately does.
|
|
117
|
+
*/
|
|
129
118
|
export type AddMemberFormValues = {
|
|
130
119
|
name: string;
|
|
131
120
|
email: string;
|
|
132
121
|
phone: string;
|
|
133
|
-
|
|
122
|
+
dobDay: string;
|
|
123
|
+
dobMonth: string;
|
|
124
|
+
dobYear: string;
|
|
134
125
|
gender: z.infer<typeof genderSchema> | null;
|
|
135
|
-
address: Address | null;
|
|
136
126
|
bloodGroup: z.infer<typeof bloodGroupSchema> | '';
|
|
137
|
-
idProofUrl: string;
|
|
138
127
|
avatarUrl: string;
|
|
139
128
|
contacts: EmergencyContactRow[];
|
|
129
|
+
/** Optional — a gym with no trainers yet, or none chosen. `''` for none. */
|
|
140
130
|
trainerId: string;
|
|
141
131
|
};
|
|
132
|
+
/**
|
|
133
|
+
* Staff keep the address a member is no longer asked for — but not an ID proof.
|
|
134
|
+
*
|
|
135
|
+
* The address stays because this is an employment record: a gym holds one for
|
|
136
|
+
* the people it EMPLOYS for reasons that have nothing to do with why it holds a
|
|
137
|
+
* member's phone number. The ID upload went for the opposite reason — nothing
|
|
138
|
+
* in the product ever showed it back, so it was a document collected and then
|
|
139
|
+
* never looked at, which is the worst thing to ask anyone for.
|
|
140
|
+
*/
|
|
142
141
|
export declare const addStaffFormSchema: z.ZodObject<{
|
|
143
142
|
role: z.ZodNullable<z.ZodEnum<{
|
|
144
143
|
trainer: "trainer";
|
|
@@ -146,15 +145,6 @@ export declare const addStaffFormSchema: z.ZodObject<{
|
|
|
146
145
|
cleaning: "cleaning";
|
|
147
146
|
reception: "reception";
|
|
148
147
|
}>> & z.ZodType<{} | undefined, "trainer" | "manager" | "cleaning" | "reception" | null, z.core.$ZodTypeInternals<{} | undefined, "trainer" | "manager" | "cleaning" | "reception" | null>>;
|
|
149
|
-
name: z.ZodString;
|
|
150
|
-
email: z.ZodEmail;
|
|
151
|
-
phone: z.ZodString;
|
|
152
|
-
dob: z.ZodString;
|
|
153
|
-
gender: z.ZodNullable<z.ZodEnum<{
|
|
154
|
-
male: "male";
|
|
155
|
-
female: "female";
|
|
156
|
-
other: "other";
|
|
157
|
-
}>> & z.ZodType<{} | undefined, "male" | "female" | "other" | null, z.core.$ZodTypeInternals<{} | undefined, "male" | "female" | "other" | null>>;
|
|
158
148
|
address: z.ZodNullable<z.ZodObject<{
|
|
159
149
|
country: z.ZodObject<{
|
|
160
150
|
id: z.ZodString;
|
|
@@ -192,6 +182,17 @@ export declare const addStaffFormSchema: z.ZodObject<{
|
|
|
192
182
|
source: z.ZodString;
|
|
193
183
|
}, z.core.$strip>>;
|
|
194
184
|
}, z.core.$strip>>;
|
|
185
|
+
name: z.ZodString;
|
|
186
|
+
email: z.ZodEmail;
|
|
187
|
+
phone: z.ZodString;
|
|
188
|
+
dobDay: z.ZodString;
|
|
189
|
+
dobMonth: z.ZodString;
|
|
190
|
+
dobYear: z.ZodString;
|
|
191
|
+
gender: z.ZodNullable<z.ZodEnum<{
|
|
192
|
+
male: "male";
|
|
193
|
+
female: "female";
|
|
194
|
+
other: "other";
|
|
195
|
+
}>> & z.ZodType<{} | undefined, "male" | "female" | "other" | null, z.core.$ZodTypeInternals<{} | undefined, "male" | "female" | "other" | null>>;
|
|
195
196
|
bloodGroup: z.ZodUnion<[z.ZodEnum<{
|
|
196
197
|
"A+": "A+";
|
|
197
198
|
"A-": "A-";
|
|
@@ -202,7 +203,6 @@ export declare const addStaffFormSchema: z.ZodObject<{
|
|
|
202
203
|
"AB+": "AB+";
|
|
203
204
|
"AB-": "AB-";
|
|
204
205
|
}>, z.ZodLiteral<"">]>;
|
|
205
|
-
idProofUrl: z.ZodString;
|
|
206
206
|
avatarUrl: z.ZodString;
|
|
207
207
|
contacts: z.ZodArray<z.ZodObject<{
|
|
208
208
|
name: z.ZodString;
|
|
@@ -212,6 +212,7 @@ export declare const addStaffFormSchema: z.ZodObject<{
|
|
|
212
212
|
}, z.core.$strip>;
|
|
213
213
|
export type AddStaffFormValues = Omit<AddMemberFormValues, 'trainerId'> & {
|
|
214
214
|
role: z.infer<typeof staffRoleSchema> | null;
|
|
215
|
+
address: Address | null;
|
|
215
216
|
};
|
|
216
217
|
/** One blank row so the section renders with a contact to fill. */
|
|
217
218
|
export declare const EMPTY_EMERGENCY_CONTACT: EmergencyContactRow;
|
|
@@ -236,15 +237,6 @@ export declare function toCreateStaffBody(values: AddStaffFormValues): CreateSta
|
|
|
236
237
|
export declare const editMemberFormSchema: z.ZodObject<{
|
|
237
238
|
trainerId: z.ZodString;
|
|
238
239
|
aadhaarLast4: z.ZodString;
|
|
239
|
-
name: z.ZodString;
|
|
240
|
-
email: z.ZodEmail;
|
|
241
|
-
phone: z.ZodString;
|
|
242
|
-
dob: z.ZodString;
|
|
243
|
-
gender: z.ZodNullable<z.ZodEnum<{
|
|
244
|
-
male: "male";
|
|
245
|
-
female: "female";
|
|
246
|
-
other: "other";
|
|
247
|
-
}>> & z.ZodType<{} | undefined, "male" | "female" | "other" | null, z.core.$ZodTypeInternals<{} | undefined, "male" | "female" | "other" | null>>;
|
|
248
240
|
address: z.ZodNullable<z.ZodObject<{
|
|
249
241
|
country: z.ZodObject<{
|
|
250
242
|
id: z.ZodString;
|
|
@@ -282,6 +274,18 @@ export declare const editMemberFormSchema: z.ZodObject<{
|
|
|
282
274
|
source: z.ZodString;
|
|
283
275
|
}, z.core.$strip>>;
|
|
284
276
|
}, z.core.$strip>>;
|
|
277
|
+
idProofUrl: z.ZodString;
|
|
278
|
+
name: z.ZodString;
|
|
279
|
+
email: z.ZodEmail;
|
|
280
|
+
phone: z.ZodString;
|
|
281
|
+
dobDay: z.ZodString;
|
|
282
|
+
dobMonth: z.ZodString;
|
|
283
|
+
dobYear: z.ZodString;
|
|
284
|
+
gender: z.ZodNullable<z.ZodEnum<{
|
|
285
|
+
male: "male";
|
|
286
|
+
female: "female";
|
|
287
|
+
other: "other";
|
|
288
|
+
}>> & z.ZodType<{} | undefined, "male" | "female" | "other" | null, z.core.$ZodTypeInternals<{} | undefined, "male" | "female" | "other" | null>>;
|
|
285
289
|
bloodGroup: z.ZodUnion<[z.ZodEnum<{
|
|
286
290
|
"A+": "A+";
|
|
287
291
|
"A-": "A-";
|
|
@@ -292,7 +296,6 @@ export declare const editMemberFormSchema: z.ZodObject<{
|
|
|
292
296
|
"AB+": "AB+";
|
|
293
297
|
"AB-": "AB-";
|
|
294
298
|
}>, z.ZodLiteral<"">]>;
|
|
295
|
-
idProofUrl: z.ZodString;
|
|
296
299
|
avatarUrl: z.ZodString;
|
|
297
300
|
contacts: z.ZodArray<z.ZodObject<{
|
|
298
301
|
name: z.ZodString;
|
|
@@ -302,6 +305,8 @@ export declare const editMemberFormSchema: z.ZodObject<{
|
|
|
302
305
|
}, z.core.$strip>;
|
|
303
306
|
export type EditMemberFormValues = AddMemberFormValues & {
|
|
304
307
|
aadhaarLast4: string;
|
|
308
|
+
address: Address | null;
|
|
309
|
+
idProofUrl: string;
|
|
305
310
|
};
|
|
306
311
|
/**
|
|
307
312
|
* Validated edit form → `PATCH /members/:id` body.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-person-form.d.ts","sourceRoot":"","sources":["../src/add-person-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,KAAK,OAAO,EAAiB,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI7C;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,wBAAwB,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"add-person-form.d.ts","sourceRoot":"","sources":["../src/add-person-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,KAAK,OAAO,EAAiB,gBAAgB,EAAE,YAA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form.js
CHANGED
|
@@ -32,6 +32,28 @@ import { staffRoleSchema } from './staff.js';
|
|
|
32
32
|
*/
|
|
33
33
|
export const ADD_PERSON_MIN_AGE_YEARS = 5;
|
|
34
34
|
export const ADD_PERSON_MAX_AGE_YEARS = 100;
|
|
35
|
+
// ─── Date of birth, as three cells ───────────────────────────────────────────
|
|
36
|
+
/**
|
|
37
|
+
* The three cells joined into the `YYYY-MM-DD` the API stores, or `undefined`
|
|
38
|
+
* when nothing was entered.
|
|
39
|
+
*
|
|
40
|
+
* Desk entry does not require a date of birth — a gym adds people with
|
|
41
|
+
* whatever it has to hand — so "blank" is a real answer and has to survive the
|
|
42
|
+
* whole way to the body as an ABSENT field rather than an empty string the
|
|
43
|
+
* API would reject.
|
|
44
|
+
*/
|
|
45
|
+
export function isoFromDobCells(day, month, year) {
|
|
46
|
+
if (!day || !month || !year)
|
|
47
|
+
return undefined;
|
|
48
|
+
return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;
|
|
49
|
+
}
|
|
50
|
+
/** A stored `YYYY-MM-DD` split back into the cells, for seeding an edit form. */
|
|
51
|
+
export function dobCellsFromIso(iso) {
|
|
52
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso ?? '');
|
|
53
|
+
if (!match)
|
|
54
|
+
return { dobDay: '', dobMonth: '', dobYear: '' };
|
|
55
|
+
return { dobYear: match[1], dobMonth: match[2], dobDay: match[3] };
|
|
56
|
+
}
|
|
35
57
|
// ─── Field-level rules ───────────────────────────────────────────────────────
|
|
36
58
|
const requiredChoice = (inner, message) => inner.nullable().refine((v) => v !== null, { message });
|
|
37
59
|
// ─── One emergency-contact row ───────────────────────────────────────────────
|
|
@@ -84,20 +106,24 @@ const addPersonBaseShape = {
|
|
|
84
106
|
name: z.string().trim().min(1, 'Name is required').max(160),
|
|
85
107
|
email: z.email('Enter a valid email'),
|
|
86
108
|
phone: z.string().regex(PHONE_REGEX, 'Enter a valid 10-digit mobile number'),
|
|
87
|
-
/** `YYYY-MM-DD` from a native date input; blank when not recorded. */
|
|
88
|
-
dob: z.string(),
|
|
89
|
-
gender: requiredChoice(genderSchema, 'Select a gender'),
|
|
90
109
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
110
|
+
* Three cells, not a native date input.
|
|
111
|
+
*
|
|
112
|
+
* `<input type="date">` renders in the BROWSER'S locale, so the same field
|
|
113
|
+
* read "mm/dd/yyyy" at an Indian gym's front desk — and a member's own
|
|
114
|
+
* onboarding asked for the very same fact through `DobInput`'s DD/MM/YYYY
|
|
115
|
+
* cells. Two surfaces collecting one fact in two formats is how a birthday
|
|
116
|
+
* gets typed the wrong way round.
|
|
117
|
+
*
|
|
118
|
+
* All three or none: desk entry does not require a date of birth, so blank
|
|
119
|
+
* is a real answer, but half a date is not.
|
|
95
120
|
*/
|
|
96
|
-
|
|
121
|
+
dobDay: z.string(),
|
|
122
|
+
dobMonth: z.string(),
|
|
123
|
+
dobYear: z.string(),
|
|
124
|
+
gender: requiredChoice(genderSchema, 'Select a gender'),
|
|
97
125
|
/** Blank when not recorded. */
|
|
98
126
|
bloodGroup: bloodGroupSchema.or(z.literal('')),
|
|
99
|
-
/** GCS URLs — both upload on pick, so these are never files. */
|
|
100
|
-
idProofUrl: z.string(),
|
|
101
127
|
avatarUrl: z.string(),
|
|
102
128
|
contacts: z.array(emergencyContactRowSchema).max(MAX_EMERGENCY_CONTACTS),
|
|
103
129
|
};
|
|
@@ -106,41 +132,34 @@ const addPersonBaseShape = {
|
|
|
106
132
|
* a mis-keyed year is the single most common desk-entry slip.
|
|
107
133
|
*/
|
|
108
134
|
function refineDob(v, ctx) {
|
|
109
|
-
|
|
135
|
+
const touched = Boolean(v.dobDay || v.dobMonth || v.dobYear);
|
|
136
|
+
// Nothing entered is fine — the desk records what it has.
|
|
137
|
+
if (!touched)
|
|
110
138
|
return;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
139
|
+
// Every message lands on `dobDay`, the first cell, because the three are one
|
|
140
|
+
// control on screen: an error parked on `dobYear` would sit under a field
|
|
141
|
+
// the form renders as a single row and reads back from `dobDay`.
|
|
142
|
+
if (!v.dobDay || !v.dobMonth || v.dobYear.length !== 4) {
|
|
143
|
+
ctx.addIssue({ code: 'custom', path: ['dobDay'], message: 'Enter the full date of birth' });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const day = Number(v.dobDay);
|
|
147
|
+
const month = Number(v.dobMonth);
|
|
148
|
+
const year = Number(v.dobYear);
|
|
149
|
+
if (!isRealDate(year, month, day)) {
|
|
150
|
+
ctx.addIssue({ code: 'custom', path: ['dobDay'], message: 'That date does not exist' });
|
|
121
151
|
return;
|
|
122
152
|
}
|
|
123
153
|
const age = ageInYears(year, month, day);
|
|
124
154
|
if (age < 0) {
|
|
125
155
|
ctx.addIssue({
|
|
126
156
|
code: 'custom',
|
|
127
|
-
path: ['
|
|
157
|
+
path: ['dobDay'],
|
|
128
158
|
message: 'Date of birth cannot be in the future',
|
|
129
159
|
});
|
|
130
160
|
}
|
|
131
|
-
else if (age < ADD_PERSON_MIN_AGE_YEARS) {
|
|
132
|
-
ctx.addIssue({
|
|
133
|
-
code: 'custom',
|
|
134
|
-
path: ['dob'],
|
|
135
|
-
message: 'Check the year of birth',
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
else if (age > ADD_PERSON_MAX_AGE_YEARS) {
|
|
139
|
-
ctx.addIssue({
|
|
140
|
-
code: 'custom',
|
|
141
|
-
path: ['dob'],
|
|
142
|
-
message: 'Check the year of birth',
|
|
143
|
-
});
|
|
161
|
+
else if (age < ADD_PERSON_MIN_AGE_YEARS || age > ADD_PERSON_MAX_AGE_YEARS) {
|
|
162
|
+
ctx.addIssue({ code: 'custom', path: ['dobDay'], message: 'Check the year of birth' });
|
|
144
163
|
}
|
|
145
164
|
}
|
|
146
165
|
// ─── Member form ─────────────────────────────────────────────────────────────
|
|
@@ -158,10 +177,25 @@ export const addMemberFormSchema = z
|
|
|
158
177
|
refineDob(v, ctx);
|
|
159
178
|
});
|
|
160
179
|
// ─── Staff form ──────────────────────────────────────────────────────────────
|
|
180
|
+
/**
|
|
181
|
+
* Staff keep the address a member is no longer asked for — but not an ID proof.
|
|
182
|
+
*
|
|
183
|
+
* The address stays because this is an employment record: a gym holds one for
|
|
184
|
+
* the people it EMPLOYS for reasons that have nothing to do with why it holds a
|
|
185
|
+
* member's phone number. The ID upload went for the opposite reason — nothing
|
|
186
|
+
* in the product ever showed it back, so it was a document collected and then
|
|
187
|
+
* never looked at, which is the worst thing to ask anyone for.
|
|
188
|
+
*/
|
|
161
189
|
export const addStaffFormSchema = z
|
|
162
190
|
.object({
|
|
163
191
|
...addPersonBaseShape,
|
|
164
192
|
role: requiredChoice(staffRoleSchema, 'Select a staff role'),
|
|
193
|
+
/**
|
|
194
|
+
* The whole address, or null. Picked through the location drawer, which
|
|
195
|
+
* hands back a complete `Address` — area chain, ids, names, ancestry,
|
|
196
|
+
* coordinates — or nothing.
|
|
197
|
+
*/
|
|
198
|
+
address: addressSchema.nullable(),
|
|
165
199
|
})
|
|
166
200
|
.superRefine((v, ctx) => {
|
|
167
201
|
refineDob(v, ctx);
|
|
@@ -171,11 +205,11 @@ const EMPTY_BASE = {
|
|
|
171
205
|
name: '',
|
|
172
206
|
email: '',
|
|
173
207
|
phone: '',
|
|
174
|
-
|
|
208
|
+
dobDay: '',
|
|
209
|
+
dobMonth: '',
|
|
210
|
+
dobYear: '',
|
|
175
211
|
gender: null,
|
|
176
|
-
address: null,
|
|
177
212
|
bloodGroup: '',
|
|
178
|
-
idProofUrl: '',
|
|
179
213
|
avatarUrl: '',
|
|
180
214
|
};
|
|
181
215
|
/** One blank row so the section renders with a contact to fill. */
|
|
@@ -193,6 +227,7 @@ export const EMPTY_ADD_STAFF_FORM = {
|
|
|
193
227
|
...EMPTY_BASE,
|
|
194
228
|
contacts: [{ ...EMPTY_EMERGENCY_CONTACT }],
|
|
195
229
|
role: null,
|
|
230
|
+
address: null,
|
|
196
231
|
};
|
|
197
232
|
// ─── Form → API body ─────────────────────────────────────────────────────────
|
|
198
233
|
/** One "Name" field on screen, `firstName` + `lastName` on the wire. */
|
|
@@ -210,10 +245,11 @@ function orUndefined(value) {
|
|
|
210
245
|
function asPhone(value) {
|
|
211
246
|
return value.replace(/\D/g, '').slice(-10);
|
|
212
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* The fields EVERY desk form sends. Address and ID proof are not among them —
|
|
250
|
+
* only two of the three forms ask for those, so each adds its own.
|
|
251
|
+
*/
|
|
213
252
|
function sharedBody(v) {
|
|
214
|
-
// Already a complete `Address` or null — the drawer cannot produce anything
|
|
215
|
-
// in between, so there is nothing to assemble or re-check here.
|
|
216
|
-
const address = v.address ?? undefined;
|
|
217
253
|
// A row with nothing in it is not a contact. Anything else has already been
|
|
218
254
|
// through `emergencyContactRowSchema`, which requires a name and a valid
|
|
219
255
|
// phone the moment a row is touched.
|
|
@@ -231,11 +267,11 @@ function sharedBody(v) {
|
|
|
231
267
|
phone: asPhone(v.phone),
|
|
232
268
|
// The form schema guarantees a choice was made before we get here.
|
|
233
269
|
gender: v.gender ?? 'other',
|
|
234
|
-
|
|
270
|
+
// Absent rather than empty when the desk did not record one — see
|
|
271
|
+
// `isoFromDobCells`.
|
|
272
|
+
dob: isoFromDobCells(v.dobDay, v.dobMonth, v.dobYear),
|
|
235
273
|
bloodGroup: v.bloodGroup === '' ? undefined : v.bloodGroup,
|
|
236
|
-
address,
|
|
237
274
|
emergencyContacts,
|
|
238
|
-
idProofUrl: orUndefined(v.idProofUrl),
|
|
239
275
|
avatarUrl: orUndefined(v.avatarUrl),
|
|
240
276
|
};
|
|
241
277
|
}
|
|
@@ -256,6 +292,9 @@ export function toCreateStaffBody(values) {
|
|
|
256
292
|
...sharedBody(values),
|
|
257
293
|
// The form schema guarantees a role was chosen.
|
|
258
294
|
role: values.role ?? 'trainer',
|
|
295
|
+
// Staff-only — see `addStaffFormSchema`. Already a complete `Address` or
|
|
296
|
+
// null; the location drawer cannot produce anything in between.
|
|
297
|
+
address: values.address ?? undefined,
|
|
259
298
|
};
|
|
260
299
|
}
|
|
261
300
|
// ─── Edit member ─────────────────────────────────────────────────────────────
|
|
@@ -277,6 +316,16 @@ export const editMemberFormSchema = z
|
|
|
277
316
|
.string()
|
|
278
317
|
.trim()
|
|
279
318
|
.refine((v) => v === '' || /^\d{4}$/.test(v), 'Enter the last four digits'),
|
|
319
|
+
/**
|
|
320
|
+
* Address and ID proof are asked HERE and not on the add form.
|
|
321
|
+
*
|
|
322
|
+
* Adding somebody happens at a desk with a queue behind them; editing
|
|
323
|
+
* happens later, once the gym actually holds the document. Dropping them
|
|
324
|
+
* from EDIT as well would leave three fields the API stores, the detail
|
|
325
|
+
* screen renders, and no screen anywhere can write.
|
|
326
|
+
*/
|
|
327
|
+
address: addressSchema.nullable(),
|
|
328
|
+
idProofUrl: z.string(),
|
|
280
329
|
})
|
|
281
330
|
.superRefine((v, ctx) => {
|
|
282
331
|
refineDob(v, ctx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-person-form.js","sourceRoot":"","sources":["../src/add-person-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAErF,OAAO,EAAgB,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1F,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,CAAC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B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,8DAA8D;IAC9D,YAAY,EAAE,CAAC;SACZ,MAAM,EAAE;SACR,IAAI,EAAE;SACN,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,4BAA4B,CAAC;CAC9E,CAAC;KACD,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;IACtB,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC;AAML;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAA4B;IAC7D,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO;QACL,GAAG,MAAM;QACT,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,IAAI;QACvB,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,IAAI;QACrC,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;QACpC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;QAClC,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,IAAI;QACxD,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE;KACpF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * gymmonk-schema — \"Add member\" / \"Add staff\" FORM schemas\n * ========================================================\n * The client-side validation contract for the owner's desk-entry forms, and the\n * mappers that turn a filled form into the `createMember` / `createStaff` API\n * bodies.\n *\n * Why these live here rather than in the client, and why they are distinct from\n * `createMemberBodySchema`: the form's working shape is not the wire shape. It\n * holds ONE \"name\" field the API splits in two, `null` for a choice not yet\n * made, and `''` for an optional value left blank. Those are legitimate mid-edit\n * states that the API body must never see. Expressing the same rules over the\n * form shape here keeps\n * every message, bound and regex defined once — the client cannot drift from\n * what the server will accept, and the coercion from one shape to the other is\n * part of the contract instead of ad-hoc code in a component.\n *\n * Mirrors `onboarding-form.ts`, which does the same job for the wizards.\n *\n * @module gymmonk-schema/add-person-form\n */\n\nimport { z } from 'zod';\nimport { ageInYears, isRealDate, PHONE_REGEX } from './common.js';\nimport type { CreateMemberBody, UpdateMemberBody } from './member.js';\nimport { emergencyContactSchema, MAX_EMERGENCY_CONTACTS } from './member-profile.js';\nimport type { AssignMembershipBody } from './membership.js';\nimport { type Address, addressSchema, bloodGroupSchema, genderSchema } from './shared.js';\nimport type { CreateStaffBody } from './staff.js';\nimport { staffRoleSchema } from './staff.js';\n\n// ─── Bounds ──────────────────────────────────────────────────────────────────\n\n/**\n * Age bounds for someone signed up at the desk. Wider than the member wizard's\n * because a gym also enrols juniors with a guardian present, and the date is\n * typed by staff rather than by the person themselves.\n */\nexport const ADD_PERSON_MIN_AGE_YEARS = 5;\nexport const ADD_PERSON_MAX_AGE_YEARS = 100;\n\n// ─── Field-level rules ───────────────────────────────────────────────────────\n\nconst requiredChoice = <T extends z.ZodTypeAny>(inner: T, message: string) =>\n inner.nullable().refine((v: unknown) => v !== null, { message });\n\n// ─── One emergency-contact row ───────────────────────────────────────────────\n\n/**\n * One emergency-contact row: WHO to call, on what number, and how they are\n * related. A row is either wholly blank (ignored) or names a person.\n *\n * ── Why `name` exists now ───────────────────────────────────────────────────\n * This form used to collect a relationship and a phone with no name at all,\n * and the mapper wrote the relationship INTO `name` because\n * `emergencyContactSchema` requires one. The member's own surfaces store a real\n * name, so the two halves of the product disagreed about what the field held,\n * and the disagreement destroyed data: a member onboards with \"Priya\", the\n * owner opens Edit Member and sees Relationship prefilled \"Priya\" (the reader\n * fell back to `name`), corrects it to \"Sister\", saves — and the contact is now\n * called Sister. Whoever has to ring that number in an emergency is left with\n * a word instead of a person.\n *\n * `relationship` stays OPTIONAL, matching `emergencyContactSchema`. It is\n * useful context, not something to block a desk entry over.\n */\nexport const emergencyContactRowSchema = z\n .object({\n name: z.string().trim().max(120),\n relationship: z.string().trim().max(60),\n phone: z.string().trim(),\n })\n .superRefine((v, ctx) => {\n const blank = v.name === '' && v.relationship === '' && v.phone === '';\n if (blank) return;\n if (v.name === '') {\n ctx.addIssue({\n code: 'custom',\n path: ['name'],\n message: \"Add the contact's name\",\n });\n }\n if (!PHONE_REGEX.test(v.phone)) {\n ctx.addIssue({\n code: 'custom',\n path: ['phone'],\n message: 'Enter a valid 10-digit mobile number',\n });\n }\n });\n\nexport interface EmergencyContactRow {\n name: string;\n relationship: string;\n phone: string;\n}\n\n// ─── Shared base ─────────────────────────────────────────────────────────────\n\nconst addPersonBaseShape = {\n /** One field on screen; split into `firstName` / `lastName` on the wire. */\n name: z.string().trim().min(1, 'Name is required').max(160),\n email: z.email('Enter a valid email'),\n phone: z.string().regex(PHONE_REGEX, 'Enter a valid 10-digit mobile number'),\n /** `YYYY-MM-DD` from a native date input; blank when not recorded. */\n dob: z.string(),\n gender: requiredChoice(genderSchema, 'Select a gender'),\n\n /**\n * The whole address, or null. Picked through the location drawer, which\n * hands back a complete `Address` — area chain, ids, names, ancestry,\n * coordinates — or nothing. It is therefore atomic: the \"half-filled\n * address\" this schema used to guard against can no longer be expressed.\n */\n address: addressSchema.nullable(),\n\n /** Blank when not recorded. */\n bloodGroup: bloodGroupSchema.or(z.literal('')),\n /** GCS URLs — both upload on pick, so these are never files. */\n idProofUrl: z.string(),\n avatarUrl: z.string(),\n\n contacts: z.array(emergencyContactRowSchema).max(MAX_EMERGENCY_CONTACTS),\n};\n\n/**\n * Date of birth is optional, but a typed one has to be real and plausible —\n * a mis-keyed year is the single most common desk-entry slip.\n */\nfunction refineDob(v: { dob: string }, ctx: z.RefinementCtx): void {\n if (v.dob === '') return;\n\n const parts = v.dob.split('-');\n const year = Number(parts[0]);\n const month = Number(parts[1]);\n const day = Number(parts[2]);\n\n if (parts.length !== 3 || !isRealDate(year, month, day)) {\n ctx.addIssue({\n code: 'custom',\n path: ['dob'],\n message: 'That date does not exist',\n });\n return;\n }\n\n const age = ageInYears(year, month, day);\n if (age < 0) {\n ctx.addIssue({\n code: 'custom',\n path: ['dob'],\n message: 'Date of birth cannot be in the future',\n });\n } else if (age < ADD_PERSON_MIN_AGE_YEARS) {\n ctx.addIssue({\n code: 'custom',\n path: ['dob'],\n message: 'Check the year of birth',\n });\n } else if (age > ADD_PERSON_MAX_AGE_YEARS) {\n ctx.addIssue({\n code: 'custom',\n path: ['dob'],\n message: 'Check the year of birth',\n });\n }\n}\n\n// ─── Member form ─────────────────────────────────────────────────────────────\n\nexport const addMemberFormSchema = z\n .object({\n ...addPersonBaseShape,\n /**\n * Central-auth user id of the trainer, or `''` for none. Only trainers who\n * have CLAIMED their invite can be assigned — an unclaimed staff record has\n * no user to point at (`MemberProfile.assignedTrainerId` refs `User`).\n */\n trainerId: z.string(),\n })\n .superRefine((v, ctx) => {\n refineDob(v, ctx);\n });\n\nexport type AddMemberFormValues = {\n name: string;\n email: string;\n phone: string;\n dob: string;\n gender: z.infer<typeof genderSchema> | null;\n address: Address | null;\n bloodGroup: z.infer<typeof bloodGroupSchema> | '';\n idProofUrl: string;\n avatarUrl: string;\n contacts: EmergencyContactRow[];\n trainerId: string;\n};\n\n// ─── Staff form ──────────────────────────────────────────────────────────────\n\nexport const addStaffFormSchema = z\n .object({\n ...addPersonBaseShape,\n role: requiredChoice(staffRoleSchema, 'Select a staff role'),\n })\n .superRefine((v, ctx) => {\n refineDob(v, ctx);\n });\n\nexport type AddStaffFormValues = Omit<AddMemberFormValues, 'trainerId'> & {\n role: z.infer<typeof staffRoleSchema> | null;\n};\n\n// ─── Empty states ────────────────────────────────────────────────────────────\n\nconst EMPTY_BASE = {\n name: '',\n email: '',\n phone: '',\n dob: '',\n gender: null,\n address: null,\n bloodGroup: '' as const,\n idProofUrl: '',\n avatarUrl: '',\n} satisfies Omit<AddMemberFormValues, 'contacts' | 'trainerId'>;\n\n/** One blank row so the section renders with a contact to fill. */\nexport const EMPTY_EMERGENCY_CONTACT: EmergencyContactRow = {\n name: '',\n relationship: '',\n phone: '',\n};\n\nexport const EMPTY_ADD_MEMBER_FORM: AddMemberFormValues = {\n ...EMPTY_BASE,\n contacts: [{ ...EMPTY_EMERGENCY_CONTACT }],\n trainerId: '',\n};\n\nexport const EMPTY_ADD_STAFF_FORM: AddStaffFormValues = {\n ...EMPTY_BASE,\n contacts: [{ ...EMPTY_EMERGENCY_CONTACT }],\n role: null,\n};\n\n// ─── Form → API body ─────────────────────────────────────────────────────────\n\n/** One \"Name\" field on screen, `firstName` + `lastName` on the wire. */\nfunction splitName(value: string): { firstName: string; lastName?: string } {\n const parts = value.trim().split(/\\s+/).filter(Boolean);\n const lastName = parts.slice(1).join(' ');\n return { firstName: parts[0] ?? '', ...(lastName ? { lastName } : {}) };\n}\n\n/** Drop a blank optional so it reads as \"not provided\" rather than `''`. */\nfunction orUndefined(value: string): string | undefined {\n const trimmed = value.trim();\n return trimmed === '' ? undefined : trimmed;\n}\n\n/** Phones are STORED raw — strip any display formatting back to 10 digits. */\nfunction asPhone(value: string): string {\n return value.replace(/\\D/g, '').slice(-10);\n}\n\nfunction sharedBody(v: Omit<AddMemberFormValues, 'trainerId'>) {\n // Already a complete `Address` or null — the drawer cannot produce anything\n // in between, so there is nothing to assemble or re-check here.\n const address = v.address ?? undefined;\n\n // A row with nothing in it is not a contact. Anything else has already been\n // through `emergencyContactRowSchema`, which requires a name and a valid\n // phone the moment a row is touched.\n const emergencyContacts = v.contacts\n .filter((c) => c.name !== '' || c.relationship !== '' || c.phone !== '')\n .map((c) =>\n emergencyContactSchema.parse({\n name: c.name.trim(),\n phone: asPhone(c.phone),\n relationship: orUndefined(c.relationship),\n }),\n )\n .slice(0, MAX_EMERGENCY_CONTACTS);\n\n return {\n ...splitName(v.name),\n email: v.email.trim(),\n phone: asPhone(v.phone),\n // The form schema guarantees a choice was made before we get here.\n gender: v.gender ?? 'other',\n dob: orUndefined(v.dob),\n bloodGroup: v.bloodGroup === '' ? undefined : v.bloodGroup,\n address,\n emergencyContacts,\n idProofUrl: orUndefined(v.idProofUrl),\n avatarUrl: orUndefined(v.avatarUrl),\n };\n}\n\n/**\n * Validated member form → `POST /members` body. `initialPlan` comes from the\n * membership step, which the form itself knows nothing about.\n */\nexport function toCreateMemberBody(\n values: AddMemberFormValues,\n initialPlan?: AssignMembershipBody,\n): CreateMemberBody {\n return {\n ...sharedBody(values),\n assignedTrainerId: orUndefined(values.trainerId),\n ...(initialPlan ? { initialPlan } : {}),\n };\n}\n\n/** Validated staff form → `POST /staff` body. */\nexport function toCreateStaffBody(values: AddStaffFormValues): CreateStaffBody {\n return {\n ...sharedBody(values),\n // The form schema guarantees a role was chosen.\n role: values.role ?? 'trainer',\n };\n}\n\n// ─── Edit member ─────────────────────────────────────────────────────────────\n\n/**\n * Editing a member reuses the add form's every rule, plus the Aadhaar last-four\n * the desk may not have taken at signup.\n *\n * It is a separate schema rather than the same one because the two forms differ\n * in what \"blank\" means. On the add form a blank optional is simply not\n * provided; on the edit form it is an instruction to CLEAR a value that is\n * already stored, and the mapper has to send `null` rather than omit the field.\n */\nexport const editMemberFormSchema = z\n .object({\n ...addPersonBaseShape,\n trainerId: z.string(),\n /** Blank when not recorded; exactly four digits otherwise. */\n aadhaarLast4: z\n .string()\n .trim()\n .refine((v) => v === '' || /^\\d{4}$/.test(v), 'Enter the last four digits'),\n })\n .superRefine((v, ctx) => {\n refineDob(v, ctx);\n });\n\nexport type EditMemberFormValues = AddMemberFormValues & {\n aadhaarLast4: string;\n};\n\n/**\n * Validated edit form → `PATCH /members/:id` body.\n *\n * Sends every field, including the cleared ones as `null`, because the owner\n * emptying a field is an edit like any other. The four identity fields go\n * along too; the server drops them once the member has claimed their account.\n */\nexport function toUpdateMemberBody(values: EditMemberFormValues): UpdateMemberBody {\n const shared = sharedBody(values);\n return {\n ...shared,\n dob: shared.dob ?? null,\n bloodGroup: shared.bloodGroup ?? null,\n address: values.address,\n idProofUrl: values.idProofUrl.trim(),\n avatarUrl: values.avatarUrl.trim(),\n assignedTrainerId: orUndefined(values.trainerId) ?? null,\n aadhaarLast4: values.aadhaarLast4.trim() === '' ? null : values.aadhaarLast4.trim(),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"add-person-form.js","sourceRoot":"","sources":["../src/add-person-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAErF,OAAO,EAAgB,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1F,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAC1C,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,gFAAgF;AAEhF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,KAAa,EAAE,IAAY;IACtE,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC9C,OAAO,GAAG,IAAI,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AACrE,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,eAAe,CAAC,GAA8B;IAK5D,MAAM,KAAK,GAAG,2BAA2B,CAAC,IAAI,CAAC,GAAG,IAA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O;QACvB,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;QACpC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;QAClC,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,IAAI;QACxD,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE;KACpF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * gymmonk-schema — \"Add member\" / \"Add staff\" FORM schemas\n * ========================================================\n * The client-side validation contract for the owner's desk-entry forms, and the\n * mappers that turn a filled form into the `createMember` / `createStaff` API\n * bodies.\n *\n * Why these live here rather than in the client, and why they are distinct from\n * `createMemberBodySchema`: the form's working shape is not the wire shape. It\n * holds ONE \"name\" field the API splits in two, `null` for a choice not yet\n * made, and `''` for an optional value left blank. Those are legitimate mid-edit\n * states that the API body must never see. Expressing the same rules over the\n * form shape here keeps\n * every message, bound and regex defined once — the client cannot drift from\n * what the server will accept, and the coercion from one shape to the other is\n * part of the contract instead of ad-hoc code in a component.\n *\n * Mirrors `onboarding-form.ts`, which does the same job for the wizards.\n *\n * @module gymmonk-schema/add-person-form\n */\n\nimport { z } from 'zod';\nimport { ageInYears, isRealDate, PHONE_REGEX } from './common.js';\nimport type { CreateMemberBody, UpdateMemberBody } from './member.js';\nimport { emergencyContactSchema, MAX_EMERGENCY_CONTACTS } from './member-profile.js';\nimport type { AssignMembershipBody } from './membership.js';\nimport { type Address, addressSchema, bloodGroupSchema, genderSchema } from './shared.js';\nimport type { CreateStaffBody } from './staff.js';\nimport { staffRoleSchema } from './staff.js';\n\n// ─── Bounds ──────────────────────────────────────────────────────────────────\n\n/**\n * Age bounds for someone signed up at the desk. Wider than the member wizard's\n * because a gym also enrols juniors with a guardian present, and the date is\n * typed by staff rather than by the person themselves.\n */\nexport const ADD_PERSON_MIN_AGE_YEARS = 5;\nexport const ADD_PERSON_MAX_AGE_YEARS = 100;\n\n// ─── Date of birth, as three cells ───────────────────────────────────────────\n\n/**\n * The three cells joined into the `YYYY-MM-DD` the API stores, or `undefined`\n * when nothing was entered.\n *\n * Desk entry does not require a date of birth — a gym adds people with\n * whatever it has to hand — so \"blank\" is a real answer and has to survive the\n * whole way to the body as an ABSENT field rather than an empty string the\n * API would reject.\n */\nexport function isoFromDobCells(day: string, month: string, year: string): string | undefined {\n if (!day || !month || !year) return undefined;\n return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;\n}\n\n/** A stored `YYYY-MM-DD` split back into the cells, for seeding an edit form. */\nexport function dobCellsFromIso(iso: string | null | undefined): {\n dobDay: string;\n dobMonth: string;\n dobYear: string;\n} {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(iso ?? '');\n if (!match) return { dobDay: '', dobMonth: '', dobYear: '' };\n return { dobYear: match[1] as string, dobMonth: match[2] as string, dobDay: match[3] as string };\n}\n\n// ─── Field-level rules ───────────────────────────────────────────────────────\n\nconst requiredChoice = <T extends z.ZodTypeAny>(inner: T, message: string) =>\n inner.nullable().refine((v: unknown) => v !== null, { message });\n\n// ─── One emergency-contact row ───────────────────────────────────────────────\n\n/**\n * One emergency-contact row: WHO to call, on what number, and how they are\n * related. A row is either wholly blank (ignored) or names a person.\n *\n * ── Why `name` exists now ───────────────────────────────────────────────────\n * This form used to collect a relationship and a phone with no name at all,\n * and the mapper wrote the relationship INTO `name` because\n * `emergencyContactSchema` requires one. The member's own surfaces store a real\n * name, so the two halves of the product disagreed about what the field held,\n * and the disagreement destroyed data: a member onboards with \"Priya\", the\n * owner opens Edit Member and sees Relationship prefilled \"Priya\" (the reader\n * fell back to `name`), corrects it to \"Sister\", saves — and the contact is now\n * called Sister. Whoever has to ring that number in an emergency is left with\n * a word instead of a person.\n *\n * `relationship` stays OPTIONAL, matching `emergencyContactSchema`. It is\n * useful context, not something to block a desk entry over.\n */\nexport const emergencyContactRowSchema = z\n .object({\n name: z.string().trim().max(120),\n relationship: z.string().trim().max(60),\n phone: z.string().trim(),\n })\n .superRefine((v, ctx) => {\n const blank = v.name === '' && v.relationship === '' && v.phone === '';\n if (blank) return;\n if (v.name === '') {\n ctx.addIssue({\n code: 'custom',\n path: ['name'],\n message: \"Add the contact's name\",\n });\n }\n if (!PHONE_REGEX.test(v.phone)) {\n ctx.addIssue({\n code: 'custom',\n path: ['phone'],\n message: 'Enter a valid 10-digit mobile number',\n });\n }\n });\n\nexport interface EmergencyContactRow {\n name: string;\n relationship: string;\n phone: string;\n}\n\n// ─── Shared base ─────────────────────────────────────────────────────────────\n\nconst addPersonBaseShape = {\n /** One field on screen; split into `firstName` / `lastName` on the wire. */\n name: z.string().trim().min(1, 'Name is required').max(160),\n email: z.email('Enter a valid email'),\n phone: z.string().regex(PHONE_REGEX, 'Enter a valid 10-digit mobile number'),\n /**\n * Three cells, not a native date input.\n *\n * `<input type=\"date\">` renders in the BROWSER'S locale, so the same field\n * read \"mm/dd/yyyy\" at an Indian gym's front desk — and a member's own\n * onboarding asked for the very same fact through `DobInput`'s DD/MM/YYYY\n * cells. Two surfaces collecting one fact in two formats is how a birthday\n * gets typed the wrong way round.\n *\n * All three or none: desk entry does not require a date of birth, so blank\n * is a real answer, but half a date is not.\n */\n dobDay: z.string(),\n dobMonth: z.string(),\n dobYear: z.string(),\n gender: requiredChoice(genderSchema, 'Select a gender'),\n\n /** Blank when not recorded. */\n bloodGroup: bloodGroupSchema.or(z.literal('')),\n avatarUrl: z.string(),\n\n contacts: z.array(emergencyContactRowSchema).max(MAX_EMERGENCY_CONTACTS),\n};\n\n/**\n * Date of birth is optional, but a typed one has to be real and plausible —\n * a mis-keyed year is the single most common desk-entry slip.\n */\nfunction refineDob(\n v: { dobDay: string; dobMonth: string; dobYear: string },\n ctx: z.RefinementCtx,\n): void {\n const touched = Boolean(v.dobDay || v.dobMonth || v.dobYear);\n // Nothing entered is fine — the desk records what it has.\n if (!touched) return;\n\n // Every message lands on `dobDay`, the first cell, because the three are one\n // control on screen: an error parked on `dobYear` would sit under a field\n // the form renders as a single row and reads back from `dobDay`.\n if (!v.dobDay || !v.dobMonth || v.dobYear.length !== 4) {\n ctx.addIssue({ code: 'custom', path: ['dobDay'], message: 'Enter the full date of birth' });\n return;\n }\n\n const day = Number(v.dobDay);\n const month = Number(v.dobMonth);\n const year = Number(v.dobYear);\n\n if (!isRealDate(year, month, day)) {\n ctx.addIssue({ code: 'custom', path: ['dobDay'], message: 'That date does not exist' });\n return;\n }\n\n const age = ageInYears(year, month, day);\n if (age < 0) {\n ctx.addIssue({\n code: 'custom',\n path: ['dobDay'],\n message: 'Date of birth cannot be in the future',\n });\n } else if (age < ADD_PERSON_MIN_AGE_YEARS || age > ADD_PERSON_MAX_AGE_YEARS) {\n ctx.addIssue({ code: 'custom', path: ['dobDay'], message: 'Check the year of birth' });\n }\n}\n\n// ─── Member form ─────────────────────────────────────────────────────────────\n\nexport const addMemberFormSchema = z\n .object({\n ...addPersonBaseShape,\n /**\n * Central-auth user id of the trainer, or `''` for none. Only trainers who\n * have CLAIMED their invite can be assigned — an unclaimed staff record has\n * no user to point at (`MemberProfile.assignedTrainerId` refs `User`).\n */\n trainerId: z.string(),\n })\n .superRefine((v, ctx) => {\n refineDob(v, ctx);\n });\n\n/**\n * Adding a member asks for the person, not their paperwork.\n *\n * No address and no ID proof: neither is something a front desk has when\n * somebody walks in, both were optional and therefore skipped, and the member's\n * own screens never collected them either. They live on the EDIT form, where an\n * owner fills them in once they actually have them, and on the staff form,\n * where an employer legitimately does.\n */\nexport type AddMemberFormValues = {\n name: string;\n email: string;\n phone: string;\n dobDay: string;\n dobMonth: string;\n dobYear: string;\n gender: z.infer<typeof genderSchema> | null;\n bloodGroup: z.infer<typeof bloodGroupSchema> | '';\n avatarUrl: string;\n contacts: EmergencyContactRow[];\n /** Optional — a gym with no trainers yet, or none chosen. `''` for none. */\n trainerId: string;\n};\n\n// ─── Staff form ──────────────────────────────────────────────────────────────\n\n/**\n * Staff keep the address a member is no longer asked for — but not an ID proof.\n *\n * The address stays because this is an employment record: a gym holds one for\n * the people it EMPLOYS for reasons that have nothing to do with why it holds a\n * member's phone number. The ID upload went for the opposite reason — nothing\n * in the product ever showed it back, so it was a document collected and then\n * never looked at, which is the worst thing to ask anyone for.\n */\nexport const addStaffFormSchema = z\n .object({\n ...addPersonBaseShape,\n role: requiredChoice(staffRoleSchema, 'Select a staff role'),\n /**\n * The whole address, or null. Picked through the location drawer, which\n * hands back a complete `Address` — area chain, ids, names, ancestry,\n * coordinates — or nothing.\n */\n address: addressSchema.nullable(),\n })\n .superRefine((v, ctx) => {\n refineDob(v, ctx);\n });\n\nexport type AddStaffFormValues = Omit<AddMemberFormValues, 'trainerId'> & {\n role: z.infer<typeof staffRoleSchema> | null;\n address: Address | null;\n};\n\n// ─── Empty states ────────────────────────────────────────────────────────────\n\nconst EMPTY_BASE = {\n name: '',\n email: '',\n phone: '',\n dobDay: '',\n dobMonth: '',\n dobYear: '',\n gender: null,\n bloodGroup: '' as const,\n avatarUrl: '',\n} satisfies Omit<AddMemberFormValues, 'contacts' | 'trainerId'>;\n\n/** One blank row so the section renders with a contact to fill. */\nexport const EMPTY_EMERGENCY_CONTACT: EmergencyContactRow = {\n name: '',\n relationship: '',\n phone: '',\n};\n\nexport const EMPTY_ADD_MEMBER_FORM: AddMemberFormValues = {\n ...EMPTY_BASE,\n contacts: [{ ...EMPTY_EMERGENCY_CONTACT }],\n trainerId: '',\n};\n\nexport const EMPTY_ADD_STAFF_FORM: AddStaffFormValues = {\n ...EMPTY_BASE,\n contacts: [{ ...EMPTY_EMERGENCY_CONTACT }],\n role: null,\n address: null,\n};\n\n// ─── Form → API body ─────────────────────────────────────────────────────────\n\n/** One \"Name\" field on screen, `firstName` + `lastName` on the wire. */\nfunction splitName(value: string): { firstName: string; lastName?: string } {\n const parts = value.trim().split(/\\s+/).filter(Boolean);\n const lastName = parts.slice(1).join(' ');\n return { firstName: parts[0] ?? '', ...(lastName ? { lastName } : {}) };\n}\n\n/** Drop a blank optional so it reads as \"not provided\" rather than `''`. */\nfunction orUndefined(value: string): string | undefined {\n const trimmed = value.trim();\n return trimmed === '' ? undefined : trimmed;\n}\n\n/** Phones are STORED raw — strip any display formatting back to 10 digits. */\nfunction asPhone(value: string): string {\n return value.replace(/\\D/g, '').slice(-10);\n}\n\n/**\n * The fields EVERY desk form sends. Address and ID proof are not among them —\n * only two of the three forms ask for those, so each adds its own.\n */\nfunction sharedBody(v: Omit<AddMemberFormValues, 'trainerId'>) {\n // A row with nothing in it is not a contact. Anything else has already been\n // through `emergencyContactRowSchema`, which requires a name and a valid\n // phone the moment a row is touched.\n const emergencyContacts = v.contacts\n .filter((c) => c.name !== '' || c.relationship !== '' || c.phone !== '')\n .map((c) =>\n emergencyContactSchema.parse({\n name: c.name.trim(),\n phone: asPhone(c.phone),\n relationship: orUndefined(c.relationship),\n }),\n )\n .slice(0, MAX_EMERGENCY_CONTACTS);\n\n return {\n ...splitName(v.name),\n email: v.email.trim(),\n phone: asPhone(v.phone),\n // The form schema guarantees a choice was made before we get here.\n gender: v.gender ?? 'other',\n // Absent rather than empty when the desk did not record one — see\n // `isoFromDobCells`.\n dob: isoFromDobCells(v.dobDay, v.dobMonth, v.dobYear),\n bloodGroup: v.bloodGroup === '' ? undefined : v.bloodGroup,\n emergencyContacts,\n avatarUrl: orUndefined(v.avatarUrl),\n };\n}\n\n/**\n * Validated member form → `POST /members` body. `initialPlan` comes from the\n * membership step, which the form itself knows nothing about.\n */\nexport function toCreateMemberBody(\n values: AddMemberFormValues,\n initialPlan?: AssignMembershipBody,\n): CreateMemberBody {\n return {\n ...sharedBody(values),\n assignedTrainerId: orUndefined(values.trainerId),\n ...(initialPlan ? { initialPlan } : {}),\n };\n}\n\n/** Validated staff form → `POST /staff` body. */\nexport function toCreateStaffBody(values: AddStaffFormValues): CreateStaffBody {\n return {\n ...sharedBody(values),\n // The form schema guarantees a role was chosen.\n role: values.role ?? 'trainer',\n // Staff-only — see `addStaffFormSchema`. Already a complete `Address` or\n // null; the location drawer cannot produce anything in between.\n address: values.address ?? undefined,\n };\n}\n\n// ─── Edit member ─────────────────────────────────────────────────────────────\n\n/**\n * Editing a member reuses the add form's every rule, plus the Aadhaar last-four\n * the desk may not have taken at signup.\n *\n * It is a separate schema rather than the same one because the two forms differ\n * in what \"blank\" means. On the add form a blank optional is simply not\n * provided; on the edit form it is an instruction to CLEAR a value that is\n * already stored, and the mapper has to send `null` rather than omit the field.\n */\nexport const editMemberFormSchema = z\n .object({\n ...addPersonBaseShape,\n trainerId: z.string(),\n /** Blank when not recorded; exactly four digits otherwise. */\n aadhaarLast4: z\n .string()\n .trim()\n .refine((v) => v === '' || /^\\d{4}$/.test(v), 'Enter the last four digits'),\n /**\n * Address and ID proof are asked HERE and not on the add form.\n *\n * Adding somebody happens at a desk with a queue behind them; editing\n * happens later, once the gym actually holds the document. Dropping them\n * from EDIT as well would leave three fields the API stores, the detail\n * screen renders, and no screen anywhere can write.\n */\n address: addressSchema.nullable(),\n idProofUrl: z.string(),\n })\n .superRefine((v, ctx) => {\n refineDob(v, ctx);\n });\n\nexport type EditMemberFormValues = AddMemberFormValues & {\n aadhaarLast4: string;\n address: Address | null;\n idProofUrl: string;\n};\n\n/**\n * Validated edit form → `PATCH /members/:id` body.\n *\n * Sends every field, including the cleared ones as `null`, because the owner\n * emptying a field is an edit like any other. The four identity fields go\n * along too; the server drops them once the member has claimed their account.\n */\nexport function toUpdateMemberBody(values: EditMemberFormValues): UpdateMemberBody {\n const shared = sharedBody(values);\n return {\n ...shared,\n dob: shared.dob ?? null,\n bloodGroup: shared.bloodGroup ?? null,\n address: values.address,\n idProofUrl: values.idProofUrl.trim(),\n avatarUrl: values.avatarUrl.trim(),\n assignedTrainerId: orUndefined(values.trainerId) ?? null,\n aadhaarLast4: values.aadhaarLast4.trim() === '' ? null : values.aadhaarLast4.trim(),\n };\n}\n"]}
|
package/dist/center.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ export declare const centerStatusSchema: z.ZodEnum<{
|
|
|
85
85
|
inactive: "inactive";
|
|
86
86
|
}>;
|
|
87
87
|
export type CenterStatus = z.infer<typeof centerStatusSchema>;
|
|
88
|
-
export {
|
|
88
|
+
export { type CenterCode, centerCodeSchema } from './codes.js';
|
|
89
89
|
export declare const createCenterBodySchema: z.ZodObject<{
|
|
90
90
|
checkInRadiusM: z.ZodOptional<z.ZodNumber>;
|
|
91
91
|
mapLinkUrl: z.ZodOptional<z.ZodString>;
|
package/dist/center.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"center.d.ts","sourceRoot":"","sources":["../src/center.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAexB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,YAAY,oTAgCf,CAAC;AACX,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;EAAuB,CAAC;AACrD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAI1D,eAAO,MAAM,kBAAkB;;;EAAiC,CAAC;AACjE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAM9D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"center.d.ts","sourceRoot":"","sources":["../src/center.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAexB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,YAAY,oTAgCf,CAAC;AACX,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;EAAuB,CAAC;A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,EAAE,qBAAqB,CAAC,GAAG,CAAC;CAC9B,CAAC,CAAC","sourcesContent":["/**\n * gymmonk-schema — Center (branch)\n * ================================\n * A physical gym location belonging to an organisation. Carries the public gym\n * code members use to join, opening hours, equipment scope, and contact info.\n * v1 memberships are single-center, so a Center is the unit a member joins.\n *\n * @module gymmonk-schema/center\n */\n\nimport { z } from 'zod';\nimport { centerCodeSchema } from './codes.js';\nimport {\n isoDateTimeSchema,\n objectIdSchema,\n optionalEmailSchema,\n optionalPhoneSchema,\n optionalTrimmedString,\n phoneSchema,\n} from './common.js';\nimport { mapLinkInputSchema, placePinSchema, timezoneSchema } from './location.js';\nimport { addressSchema, weeklyHoursSchema } from './shared.js';\n\n// ─── Center type ─────────────────────────────────────────────────────────────\n\n/**\n * What a centre OFFERS, multi-select.\n *\n * ── The axis, and why `personal-training` is gone ───────────────────────────\n * Every value here answers one question: what does somebody DO at this place.\n * That makes them disciplines and training modalities, so an owner ticking\n * three of them describes a real branch and a member reading them knows what\n * they are walking into.\n *\n * `personal-training` answered a different question — HOW coaching is\n * delivered, one-to-one instead of in a class — and nearly every gym in the\n * list offers it. A value almost everyone can tick separates nobody from\n * anybody, which is the opposite of what a type is for. Business model\n * (big-box, boutique, 24-hour) is a third axis again, and one this product\n * already answers better elsewhere: floor area and opening hours are recorded\n * fields, not a guess from a chip.\n *\n * ── Where the list comes from ───────────────────────────────────────────────\n * Cross-referenced rather than invented: Google Business Profile's fitness\n * categories (what gyms actually file themselves under, and therefore what\n * members search), ClassPass and Mindbody's activity taxonomies, and the\n * formats the Indian market actually runs — cult.fit's S&C, HRX, boxing, dance\n * fitness and yoga, plus the bodybuilding and martial-arts traditions that a\n * list drawn only from US sources would miss entirely.\n *\n * Deliberately NOT included, so the next person does not re-litigate it:\n * rock climbing, gymnastics and aerial/pole are real facility categories but\n * not gyms in the sense this product manages; women-only and kids' fitness\n * describe an AUDIENCE, not an activity; 24-hour and big-box describe hours\n * and size, both of which are already their own fields.\n *\n * Values are stable slugs — the LABELS are the frontend's business, so\n * rewording a chip never rewrites stored data.\n *\n * ── The field is called `types`; the screen says \"What this center offers\" ──\n * That divergence is deliberate, not an oversight. \"Type\" reads as one thing a\n * place IS, and a real branch runs several — a weights floor, a yoga room and\n * Zumba on weekends — so a singular-sounding label pushed owners to pick one\n * and misdescribe themselves. (The picker was once a single-select with a\n * \"Mixed\" option that saved as plain `gym`, which is how a CrossFit-and-boxing\n * branch came back as neither.) The label was changed to match what is stored;\n * the identifiers were not, because the values are a wire contract and\n * renaming them would rewrite data to fix a word.\n */\nexport const CENTER_TYPES = [\n // General\n 'gym',\n // Strength\n 'strength',\n 'crossfit',\n 'functional',\n 'bodybuilding',\n 'powerlifting',\n 'calisthenics',\n // Cardio & group training\n 'cardio',\n 'hiit',\n 'spinning',\n 'bootcamp',\n 'aerobics',\n 'sports-conditioning',\n // Mind & body\n 'yoga',\n 'pilates',\n 'meditation',\n // Dance\n 'zumba',\n 'dance',\n // Combat\n 'boxing',\n 'kickboxing',\n 'mma',\n 'martial-arts',\n // Facilities\n 'swimming',\n 'physiotherapy',\n] as const;\nexport const centerTypeSchema = z.enum(CENTER_TYPES);\nexport type CenterType = z.infer<typeof centerTypeSchema>;\n\n// ─── Status ──────────────────────────────────────────────────────────────────\n\nexport const centerStatusSchema = z.enum(['active', 'inactive']);\nexport type CenterStatus = z.infer<typeof centerStatusSchema>;\n\n// The public gym code (`IRN-1-7K2M`) is defined in `codes.ts` alongside the\n// member ids built on the same stem, so the four identifier shapes this product\n// issues can be read — and kept from colliding — in one place. Re-exported here\n// because a centre's code is a fact about a centre.\nexport { centerCodeSchema, type CenterCode } from './codes.js';\n\n// ─── Create / update bodies ──────────────────────────────────────────────────\n\nexport const createCenterBodySchema = z.object({\n name: z.string().trim().min(1, 'Center name is required').max(160),\n description: optionalTrimmedString(2000),\n types: z.array(centerTypeSchema).min(1, 'Pick at least one'),\n address: addressSchema,\n /** Usable floor area in square feet. */\n floorAreaSqft: z.number().int().min(0).max(1_000_000).optional(),\n /**\n * How many people the branch holds at once.\n *\n * The denominator behind \"how full are we\" — the centre detail screen shows\n * it beside the active-member count, and crowd-load has no meaning without\n * it. Optional: a gym that has never measured it should not be blocked from\n * saving the rest of its details.\n */\n capacity: z.number().int().min(1).max(100_000).optional(),\n primaryPhone: phoneSchema,\n secondaryPhone: optionalPhoneSchema,\n email: optionalEmailSchema,\n website: optionalTrimmedString(200),\n hours: weeklyHoursSchema,\n /** Uploaded gallery image URLs. */\n photos: z.array(z.string().trim().max(2000)).max(20).default([]),\n /**\n * A pasted Google Maps link. The server reads the coordinates out of it; the\n * client never sends them.\n *\n * This is the pin attendance is measured against, and it is NOT the same as\n * `address.coords`: that is an area centroid resolved from master data, which\n * can be a whole district's midpoint and is useless for proximity.\n */\n ...mapLinkInputSchema.shape,\n /**\n * How close a member must be for a check-in to count, metres. Optional — the\n * server applies its own default when a gym has not chosen one.\n */\n checkInRadiusM: z.number().int().min(50).max(5000).optional(),\n});\nexport type CreateCenterBody = z.infer<typeof createCenterBodySchema>;\n\nexport const updateCenterBodySchema = createCenterBodySchema.partial();\nexport type UpdateCenterBody = z.infer<typeof updateCenterBodySchema>;\n\n// ─── Entity (API response) ───────────────────────────────────────────────────\n\nexport const centerSchema = z.object({\n id: objectIdSchema,\n organisationId: objectIdSchema,\n /** Public join code, `IRN-1-7K2M`. */\n code: centerCodeSchema,\n /**\n * Which centre this is within its organisation — 1 for the first branch the\n * owner opened, 2 for the next.\n *\n * Stored rather than counted on read, because it is baked into this centre's\n * code AND into every member id the centre issues. Deleting branch 2 must not\n * renumber branch 3 into codes that are already printed.\n */\n sequence: z.number().int().positive(),\n name: z.string(),\n description: z.string().nullable(),\n types: z.array(centerTypeSchema),\n address: addressSchema,\n floorAreaSqft: z.number().int().nullable(),\n capacity: z.number().int().nullable(),\n primaryPhone: z.string(),\n secondaryPhone: z.string().nullable(),\n email: z.string().nullable(),\n website: z.string().nullable(),\n hours: weeklyHoursSchema,\n photos: z.array(z.string()),\n status: centerStatusSchema,\n /** Denormalised active-member count for roster headers. */\n memberCount: z.number().int().nonnegative(),\n // The resolved pin. Absent until an owner pastes a Maps link, which is why\n // attendance is unenforceable rather than failing for a gym without one.\n ...placePinSchema.shape,\n checkInRadiusM: z.number().int().nullable().optional(),\n /**\n * The centre's own timezone, as an IANA identifier (\"Asia/Kolkata\").\n *\n * WHY THE CENTRE'S AND NOT THE VIEWER'S. Attendance is filed under a calendar\n * DAY, and a day is not timezone-free — whichever zone derives it defines when\n * it starts. Deriving it from whoever is looking would put one visit on\n * different days for the member and the owner, and would make an owner's daily\n * roll-up change depending on where they opened the app. A visit belongs to the\n * gym's operating day; only the display of times follows the reader.\n *\n * An IANA NAME, never a UTC offset. Offsets are a property of an instant, not\n * of a place: they move with DST, so a stored \"+05:30\" is already wrong for\n * half the year anywhere that observes it.\n *\n * Server-derived from the centre's pin, never accepted from a client — the\n * same rule the coordinates follow, and for the same reason.\n */\n timezone: timezoneSchema,\n createdAt: isoDateTimeSchema,\n updatedAt: isoDateTimeSchema,\n});\nexport type Center = z.infer<typeof centerSchema>;\n\n// ─── Center stats (owner detail header) ──────────────────────────────────────\n\n/**\n * The three-up header on a centre's detail screen.\n *\n * Computed, never stored — `activeMembers` counts live memberships and\n * `monthlyRevenueInr` sums this month's successful payments, so the card can\n * never drift from the ledger the way a denormalised total would. `capacity`\n * is the one stored value, and is null until the owner fills it in.\n */\nexport const centerStatsSchema = z.object({\n capacity: z.number().int().nullable(),\n activeMembers: z.number().int().nonnegative(),\n monthlyRevenueInr: z.number().nonnegative(),\n});\nexport type CenterStats = z.infer<typeof centerStatsSchema>;\n\n// ─── Gym directory (member \"find a gym\") ─────────────────────────────────────\n\n/** A lightweight public directory result for the \"find a gym\" screen. */\nexport const nearbyGymSchema = z.object({\n id: objectIdSchema,\n code: centerCodeSchema,\n name: z.string(),\n /** The narrowest place name we hold (locality → district → state). */\n area: z.string(),\n district: z.string().nullable(),\n state: z.string().nullable(),\n /**\n * Kilometres from the coordinates the caller supplied.\n *\n * NULL, not 0, when it cannot be computed — the caller sent no position, or\n * the gym's address carries no coordinates. Zero is a real distance (\"you are\n * standing in it\") and using it as the unknown value put every un-geocoded\n * gym at the top of a nearest-first list.\n */\n distanceKm: z.number().nonnegative().nullable(),\n memberCount: z.number().int().nonnegative().optional(),\n});\nexport type NearbyGym = z.infer<typeof nearbyGymSchema>;\n\n/**\n * The gym directory has THREE ways in, and they differ in how far they reach.\n *\n * `code` exact public gym id — matches anywhere in the country, because\n * a member holding the id already knows which gym they mean and\n * may well be joining one in another state.\n * `q` name search — deliberately narrowed to ONE STATE. Gym names\n * repeat heavily (\"Fitness First\"), so a nationwide name search\n * returns a list nobody can pick from.\n * `districtId` browse — the gyms around them, nearest first when they share\n * their position.\n *\n * `stateId` / `districtId` are master-area ids (`area.ts`), matched against the\n * address `ancestry` array every center stores.\n */\nexport const GYM_SEARCH_MAX_RESULTS = 20;\n\nexport const gymSearchQuerySchema = z\n .object({\n /** Exact public gym id, e.g. `GYM-2025-001`. Unscoped by geography. */\n code: optionalTrimmedString(40),\n /** Name fragment. Requires `stateId`. */\n q: optionalTrimmedString(120),\n stateId: optionalTrimmedString(40),\n districtId: optionalTrimmedString(40),\n lat: z.coerce.number().min(-90).max(90).optional(),\n lng: z.coerce.number().min(-180).max(180).optional(),\n limit: z.coerce\n .number()\n .int()\n .min(1)\n .max(GYM_SEARCH_MAX_RESULTS)\n .default(GYM_SEARCH_MAX_RESULTS),\n })\n .refine((v) => !v.q || Boolean(v.stateId), {\n message: 'Pick a state to search gyms by name',\n path: ['stateId'],\n })\n .refine((v) => Boolean(v.code || v.q || v.stateId || v.districtId), {\n message: 'Enter a gym id, or pick where to look',\n path: ['stateId'],\n });\nexport type GymSearchQuery = z.infer<typeof gymSearchQuerySchema>;\n\n/**\n * The directory response.\n *\n * `truncated` says the district holds more gyms than were returned, which is\n * what the screen turns into \"showing the 20 nearest — enter a gym id if yours\n * is not here\" rather than letting the member assume their gym is absent.\n */\nexport const gymSearchResultSchema = z.object({\n items: z.array(nearbyGymSchema),\n total: z.number().int().nonnegative(),\n truncated: z.boolean(),\n});\nexport type GymSearchResult = z.infer<typeof gymSearchResultSchema>;\n\n// ─── Retained: nearby-gyms query ─────────────────────────────────────────────\n// Kept for the gym-search route the owner console's repo still serves. See the\n// note in `onboarding.ts`.\nexport const nearbyGymsQuerySchema = z.object({\n lat: z.coerce.number().min(-90).max(90).optional(),\n lng: z.coerce.number().min(-180).max(180).optional(),\n q: optionalTrimmedString(120),\n});\nexport type NearbyGymsQuery = z.infer<typeof nearbyGymsQuerySchema>;\n"]}
|
|
1
|
+
{"version":3,"file":"center.js","sourceRoot":"","sources":["../src/center.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE/D,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,UAAU;IACV,KAAK;IACL,WAAW;IACX,UAAU;IACV,UAAU;IACV,YAAY;IACZ,cAAc;IACd,cAAc;IACd,cAAc;IACd,0BAA0B;IAC1B,QAAQ;IACR,MAAM;IACN,UAAU;IACV,UAAU;IACV,UAAU;IACV,qBAAqB;IACrB,cAAc;IACd,MAAM;IACN,SAAS;IACT,YAAY;IACZ,QAAQ;IACR,OAAO;IACP,OAAO;IACP,SAAS;IACT,QAAQ;IACR,YAAY;IACZ,K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;IAC9C,IAAI,EAAE,CAAC,SAAS,CAAC;CAClB,CAAC;KACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,UAAU,CAAC,EAAE;IAClE,OAAO,EAAE,uCAAuC;IAChD,IAAI,EAAE,CAAC,SAAS,CAAC;CAClB,CAAC,CAAC;AAGL;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC;IAC/B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;IACrC,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;CACvB,CAAC,CAAC;AAGH,gFAAgF;AAChF,+EAA+E;AAC/E,2BAA2B;AAC3B,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;IAClD,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;IACpD,CAAC,EAAE,qBAAqB,CAAC,GAAG,CAAC;CAC9B,CAAC,CAAC","sourcesContent":["/**\n * gymmonk-schema — Center (branch)\n * ================================\n * A physical gym location belonging to an organisation. Carries the public gym\n * code members use to join, opening hours, equipment scope, and contact info.\n * v1 memberships are single-center, so a Center is the unit a member joins.\n *\n * @module gymmonk-schema/center\n */\n\nimport { z } from 'zod';\nimport { centerCodeSchema } from './codes.js';\nimport {\n isoDateTimeSchema,\n objectIdSchema,\n optionalEmailSchema,\n optionalPhoneSchema,\n optionalTrimmedString,\n phoneSchema,\n} from './common.js';\nimport { mapLinkInputSchema, placePinSchema, timezoneSchema } from './location.js';\nimport { addressSchema, weeklyHoursSchema } from './shared.js';\n\n// ─── Center type ─────────────────────────────────────────────────────────────\n\n/**\n * What a centre OFFERS, multi-select.\n *\n * ── The axis, and why `personal-training` is gone ───────────────────────────\n * Every value here answers one question: what does somebody DO at this place.\n * That makes them disciplines and training modalities, so an owner ticking\n * three of them describes a real branch and a member reading them knows what\n * they are walking into.\n *\n * `personal-training` answered a different question — HOW coaching is\n * delivered, one-to-one instead of in a class — and nearly every gym in the\n * list offers it. A value almost everyone can tick separates nobody from\n * anybody, which is the opposite of what a type is for. Business model\n * (big-box, boutique, 24-hour) is a third axis again, and one this product\n * already answers better elsewhere: floor area and opening hours are recorded\n * fields, not a guess from a chip.\n *\n * ── Where the list comes from ───────────────────────────────────────────────\n * Cross-referenced rather than invented: Google Business Profile's fitness\n * categories (what gyms actually file themselves under, and therefore what\n * members search), ClassPass and Mindbody's activity taxonomies, and the\n * formats the Indian market actually runs — cult.fit's S&C, HRX, boxing, dance\n * fitness and yoga, plus the bodybuilding and martial-arts traditions that a\n * list drawn only from US sources would miss entirely.\n *\n * Deliberately NOT included, so the next person does not re-litigate it:\n * rock climbing, gymnastics and aerial/pole are real facility categories but\n * not gyms in the sense this product manages; women-only and kids' fitness\n * describe an AUDIENCE, not an activity; 24-hour and big-box describe hours\n * and size, both of which are already their own fields.\n *\n * Values are stable slugs — the LABELS are the frontend's business, so\n * rewording a chip never rewrites stored data.\n *\n * ── The field is called `types`; the screen says \"What this center offers\" ──\n * That divergence is deliberate, not an oversight. \"Type\" reads as one thing a\n * place IS, and a real branch runs several — a weights floor, a yoga room and\n * Zumba on weekends — so a singular-sounding label pushed owners to pick one\n * and misdescribe themselves. (The picker was once a single-select with a\n * \"Mixed\" option that saved as plain `gym`, which is how a CrossFit-and-boxing\n * branch came back as neither.) The label was changed to match what is stored;\n * the identifiers were not, because the values are a wire contract and\n * renaming them would rewrite data to fix a word.\n */\nexport const CENTER_TYPES = [\n // General\n 'gym',\n // Strength\n 'strength',\n 'crossfit',\n 'functional',\n 'bodybuilding',\n 'powerlifting',\n 'calisthenics',\n // Cardio & group training\n 'cardio',\n 'hiit',\n 'spinning',\n 'bootcamp',\n 'aerobics',\n 'sports-conditioning',\n // Mind & body\n 'yoga',\n 'pilates',\n 'meditation',\n // Dance\n 'zumba',\n 'dance',\n // Combat\n 'boxing',\n 'kickboxing',\n 'mma',\n 'martial-arts',\n // Facilities\n 'swimming',\n 'physiotherapy',\n] as const;\nexport const centerTypeSchema = z.enum(CENTER_TYPES);\nexport type CenterType = z.infer<typeof centerTypeSchema>;\n\n// ─── Status ──────────────────────────────────────────────────────────────────\n\nexport const centerStatusSchema = z.enum(['active', 'inactive']);\nexport type CenterStatus = z.infer<typeof centerStatusSchema>;\n\n// The public gym code (`IRN-1-7K2M`) is defined in `codes.ts` alongside the\n// member ids built on the same stem, so the four identifier shapes this product\n// issues can be read — and kept from colliding — in one place. Re-exported here\n// because a centre's code is a fact about a centre.\nexport { type CenterCode, centerCodeSchema } from './codes.js';\n\n// ─── Create / update bodies ──────────────────────────────────────────────────\n\nexport const createCenterBodySchema = z.object({\n name: z.string().trim().min(1, 'Center name is required').max(160),\n description: optionalTrimmedString(2000),\n types: z.array(centerTypeSchema).min(1, 'Pick at least one'),\n address: addressSchema,\n /** Usable floor area in square feet. */\n floorAreaSqft: z.number().int().min(0).max(1_000_000).optional(),\n /**\n * How many people the branch holds at once.\n *\n * The denominator behind \"how full are we\" — the centre detail screen shows\n * it beside the active-member count, and crowd-load has no meaning without\n * it. Optional: a gym that has never measured it should not be blocked from\n * saving the rest of its details.\n */\n capacity: z.number().int().min(1).max(100_000).optional(),\n primaryPhone: phoneSchema,\n secondaryPhone: optionalPhoneSchema,\n email: optionalEmailSchema,\n website: optionalTrimmedString(200),\n hours: weeklyHoursSchema,\n /** Uploaded gallery image URLs. */\n photos: z.array(z.string().trim().max(2000)).max(20).default([]),\n /**\n * A pasted Google Maps link. The server reads the coordinates out of it; the\n * client never sends them.\n *\n * This is the pin attendance is measured against, and it is NOT the same as\n * `address.coords`: that is an area centroid resolved from master data, which\n * can be a whole district's midpoint and is useless for proximity.\n */\n ...mapLinkInputSchema.shape,\n /**\n * How close a member must be for a check-in to count, metres. Optional — the\n * server applies its own default when a gym has not chosen one.\n */\n checkInRadiusM: z.number().int().min(50).max(5000).optional(),\n});\nexport type CreateCenterBody = z.infer<typeof createCenterBodySchema>;\n\nexport const updateCenterBodySchema = createCenterBodySchema.partial();\nexport type UpdateCenterBody = z.infer<typeof updateCenterBodySchema>;\n\n// ─── Entity (API response) ───────────────────────────────────────────────────\n\nexport const centerSchema = z.object({\n id: objectIdSchema,\n organisationId: objectIdSchema,\n /** Public join code, `IRN-1-7K2M`. */\n code: centerCodeSchema,\n /**\n * Which centre this is within its organisation — 1 for the first branch the\n * owner opened, 2 for the next.\n *\n * Stored rather than counted on read, because it is baked into this centre's\n * code AND into every member id the centre issues. Deleting branch 2 must not\n * renumber branch 3 into codes that are already printed.\n */\n sequence: z.number().int().positive(),\n name: z.string(),\n description: z.string().nullable(),\n types: z.array(centerTypeSchema),\n address: addressSchema,\n floorAreaSqft: z.number().int().nullable(),\n capacity: z.number().int().nullable(),\n primaryPhone: z.string(),\n secondaryPhone: z.string().nullable(),\n email: z.string().nullable(),\n website: z.string().nullable(),\n hours: weeklyHoursSchema,\n photos: z.array(z.string()),\n status: centerStatusSchema,\n /** Denormalised active-member count for roster headers. */\n memberCount: z.number().int().nonnegative(),\n // The resolved pin. Absent until an owner pastes a Maps link, which is why\n // attendance is unenforceable rather than failing for a gym without one.\n ...placePinSchema.shape,\n checkInRadiusM: z.number().int().nullable().optional(),\n /**\n * The centre's own timezone, as an IANA identifier (\"Asia/Kolkata\").\n *\n * WHY THE CENTRE'S AND NOT THE VIEWER'S. Attendance is filed under a calendar\n * DAY, and a day is not timezone-free — whichever zone derives it defines when\n * it starts. Deriving it from whoever is looking would put one visit on\n * different days for the member and the owner, and would make an owner's daily\n * roll-up change depending on where they opened the app. A visit belongs to the\n * gym's operating day; only the display of times follows the reader.\n *\n * An IANA NAME, never a UTC offset. Offsets are a property of an instant, not\n * of a place: they move with DST, so a stored \"+05:30\" is already wrong for\n * half the year anywhere that observes it.\n *\n * Server-derived from the centre's pin, never accepted from a client — the\n * same rule the coordinates follow, and for the same reason.\n */\n timezone: timezoneSchema,\n createdAt: isoDateTimeSchema,\n updatedAt: isoDateTimeSchema,\n});\nexport type Center = z.infer<typeof centerSchema>;\n\n// ─── Center stats (owner detail header) ──────────────────────────────────────\n\n/**\n * The three-up header on a centre's detail screen.\n *\n * Computed, never stored — `activeMembers` counts live memberships and\n * `monthlyRevenueInr` sums this month's successful payments, so the card can\n * never drift from the ledger the way a denormalised total would. `capacity`\n * is the one stored value, and is null until the owner fills it in.\n */\nexport const centerStatsSchema = z.object({\n capacity: z.number().int().nullable(),\n activeMembers: z.number().int().nonnegative(),\n monthlyRevenueInr: z.number().nonnegative(),\n});\nexport type CenterStats = z.infer<typeof centerStatsSchema>;\n\n// ─── Gym directory (member \"find a gym\") ─────────────────────────────────────\n\n/** A lightweight public directory result for the \"find a gym\" screen. */\nexport const nearbyGymSchema = z.object({\n id: objectIdSchema,\n code: centerCodeSchema,\n name: z.string(),\n /** The narrowest place name we hold (locality → district → state). */\n area: z.string(),\n district: z.string().nullable(),\n state: z.string().nullable(),\n /**\n * Kilometres from the coordinates the caller supplied.\n *\n * NULL, not 0, when it cannot be computed — the caller sent no position, or\n * the gym's address carries no coordinates. Zero is a real distance (\"you are\n * standing in it\") and using it as the unknown value put every un-geocoded\n * gym at the top of a nearest-first list.\n */\n distanceKm: z.number().nonnegative().nullable(),\n memberCount: z.number().int().nonnegative().optional(),\n});\nexport type NearbyGym = z.infer<typeof nearbyGymSchema>;\n\n/**\n * The gym directory has THREE ways in, and they differ in how far they reach.\n *\n * `code` exact public gym id — matches anywhere in the country, because\n * a member holding the id already knows which gym they mean and\n * may well be joining one in another state.\n * `q` name search — deliberately narrowed to ONE STATE. Gym names\n * repeat heavily (\"Fitness First\"), so a nationwide name search\n * returns a list nobody can pick from.\n * `districtId` browse — the gyms around them, nearest first when they share\n * their position.\n *\n * `stateId` / `districtId` are master-area ids (`area.ts`), matched against the\n * address `ancestry` array every center stores.\n */\nexport const GYM_SEARCH_MAX_RESULTS = 20;\n\nexport const gymSearchQuerySchema = z\n .object({\n /** Exact public gym id, e.g. `GYM-2025-001`. Unscoped by geography. */\n code: optionalTrimmedString(40),\n /** Name fragment. Requires `stateId`. */\n q: optionalTrimmedString(120),\n stateId: optionalTrimmedString(40),\n districtId: optionalTrimmedString(40),\n lat: z.coerce.number().min(-90).max(90).optional(),\n lng: z.coerce.number().min(-180).max(180).optional(),\n limit: z.coerce\n .number()\n .int()\n .min(1)\n .max(GYM_SEARCH_MAX_RESULTS)\n .default(GYM_SEARCH_MAX_RESULTS),\n })\n .refine((v) => !v.q || Boolean(v.stateId), {\n message: 'Pick a state to search gyms by name',\n path: ['stateId'],\n })\n .refine((v) => Boolean(v.code || v.q || v.stateId || v.districtId), {\n message: 'Enter a gym id, or pick where to look',\n path: ['stateId'],\n });\nexport type GymSearchQuery = z.infer<typeof gymSearchQuerySchema>;\n\n/**\n * The directory response.\n *\n * `truncated` says the district holds more gyms than were returned, which is\n * what the screen turns into \"showing the 20 nearest — enter a gym id if yours\n * is not here\" rather than letting the member assume their gym is absent.\n */\nexport const gymSearchResultSchema = z.object({\n items: z.array(nearbyGymSchema),\n total: z.number().int().nonnegative(),\n truncated: z.boolean(),\n});\nexport type GymSearchResult = z.infer<typeof gymSearchResultSchema>;\n\n// ─── Retained: nearby-gyms query ─────────────────────────────────────────────\n// Kept for the gym-search route the owner console's repo still serves. See the\n// note in `onboarding.ts`.\nexport const nearbyGymsQuerySchema = z.object({\n lat: z.coerce.number().min(-90).max(90).optional(),\n lng: z.coerce.number().min(-180).max(180).optional(),\n q: optionalTrimmedString(120),\n});\nexport type NearbyGymsQuery = z.infer<typeof nearbyGymsQuerySchema>;\n"]}
|
package/dist/enrolment.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enrolment.js","sourceRoot":"","sources":["../src/enrolment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEhE,gFAAgF;AAEhF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAGtF,gFAAgF;AAEhF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,EAAE,EAAE,cAAc;IAClB,QAAQ,EAAE,cAAc;IACxB;;;;;;;;OAQG;IACH,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,yDAAyD;IACzD,aAAa,EAAE,mBAAmB;IAClC;;;OAGG;IACH,MAAM,EAAE,cAAc,CAAC,QAAQ,EAAE;IACjC,MAAM,EAAE,qBAAqB;IAC7B,mEAAmE;IACnE,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,2DAA2D;IAC3D,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,SAAS,EAAE,iBAAiB,CAAC,QAAQ,EAAE;IACvC;;;;;;OAMG;IACH,QAAQ,EAAE,iBAAiB;IAC3B,sCAAsC;IACtC,MAAM,EAAE,iBAAiB,CAAC,QAAQ,E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,QAAQ,EAAE;IACjC,MAAM,EAAE,qBAAqB;IAC7B,mEAAmE;IACnE,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,2DAA2D;IAC3D,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,SAAS,EAAE,iBAAiB,CAAC,QAAQ,EAAE;IACvC;;;;;;OAMG;IACH,QAAQ,EAAE,iBAAiB;IAC3B,sCAAsC;IACtC,MAAM,EAAE,iBAAiB,CAAC,QAAQ,EAAE;IACpC,6DAA6D;IAC7D,qBAAqB,EAAE,cAAc,CAAC,QAAQ,EAAE;IAChD,kDAAkD;IAClD,iBAAiB,EAAE,cAAc,CAAC,QAAQ,EAAE;IAC5C,SAAS,EAAE,iBAAiB;IAC5B,SAAS,EAAE,iBAAiB;CAC7B,CAAC,CAAC;AAGH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,eAAe,CAAC,IAAI,CAAC;IACzD,EAAE,EAAE,IAAI;IACR,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,IAAI;IACnB,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,IAAI;IACd,qBAAqB,EAAE,IAAI;CAC5B,CAAC,CAAC","sourcesContent":["/**\n * gymmonk-schema — Enrolment (a person at one gym)\n * ================================================\n * The record of somebody training at one centre: their member id there, how\n * they got in, and when it ended. One row per STINT, so leaving and coming\n * back two years later produces two rows and two member ids, and the gym keeps\n * both.\n *\n * WHY THIS IS NOT A FIELD ON THE MEMBER PROFILE. It used to be — a `centerId`\n * that was set on joining and nulled on leaving. That shape can only ever\n * describe the present: it cannot say when somebody joined, that they left, or\n * that they were once here before, and it forces one person's identity and one\n * gym's roster entry to share a lifecycle they do not have. Splitting them is\n * what makes all of the following true at once:\n *\n * - a gym can create a member at the desk before that person has an account\n * (the enrolment exists; `userId` is filled in later, at claim)\n * - one person keeps ONE identity across every gym they ever train at\n * (`MemberProfile`, and the GymMonk id on it)\n * - each gym issues its OWN member id, and reissues a fresh one if the same\n * person returns\n * - leaving is recorded rather than erased\n *\n * @module gymmonk-schema/enrolment\n */\n\nimport { z } from 'zod';\nimport { gymMemberCodeSchema } from './codes.js';\nimport { isoDateTimeSchema, objectIdSchema } from './common.js';\n\n// ─── Status ──────────────────────────────────────────────────────────────────\n\n/**\n * Where an enrolment stands.\n *\n * `invited` the desk created the record; nobody has claimed it yet. The\n * roster counts and serves these fully — a gym that has written\n * somebody down has a member, whether or not that person has\n * installed anything.\n * `active` they train here now.\n * `left` they ended it themselves.\n * `removed` the gym ended it.\n *\n * `left` and `removed` are separate states rather than one `ended` because the\n * gym asks different questions of each (churn versus enforcement), and because\n * only a removal is something an owner may want to undo.\n */\nexport const enrolmentStatusSchema = z.enum(['invited', 'active', 'left', 'removed']);\nexport type EnrolmentStatus = z.infer<typeof enrolmentStatusSchema>;\n\n// ─── Entity (API response) ───────────────────────────────────────────────────\n\nexport const enrolmentSchema = z.object({\n id: objectIdSchema,\n centerId: objectIdSchema,\n /**\n * The gym's name, resolved server-side.\n *\n * Rides along because a member CANNOT look it up: the `/centers` router\n * requires `manage Center`, so a member asking for the name of their own gym\n * gets a 403. Resolved per request rather than stored, so a gym that renames\n * itself is immediately correct everywhere instead of leaving a stale copy on\n * every enrolment it has ever issued.\n */\n centerName: z.string().nullable(),\n /** This gym's member id for this person, `IRN1-0042`. */\n gymMemberCode: gymMemberCodeSchema,\n /**\n * The claimed account. NULL while `invited` — the desk creates the record\n * from whatever it has, often before the person has signed up at all.\n */\n userId: objectIdSchema.nullable(),\n status: enrolmentStatusSchema,\n /** The address the invite was issued to; a claim must match it. */\n inviteEmail: z.string().nullable(),\n /** WhatsApp number the owner shares the invite link on. */\n invitePhone: z.string().nullable(),\n claimedAt: isoDateTimeSchema.nullable(),\n /**\n * When the gym enrolled them — the DESK's date, not the claim's.\n *\n * \"How long have they been a member\" is answered from the day the gym wrote\n * them down, which is often weeks before they get round to installing the\n * app, and is the date the gym itself would give.\n */\n joinedAt: isoDateTimeSchema,\n /** When it ended. Null while live. */\n leftAt: isoDateTimeSchema.nullable(),\n /** The workout plan the gym assigned, scoped to THIS gym. */\n assignedWorkoutPlanId: objectIdSchema.nullable(),\n /** The trainer looking after them at THIS gym. */\n assignedTrainerId: objectIdSchema.nullable(),\n createdAt: isoDateTimeSchema,\n updatedAt: isoDateTimeSchema,\n});\nexport type Enrolment = z.infer<typeof enrolmentSchema>;\n\n/**\n * The member's own view of where they train, embedded in their profile.\n *\n * A narrowed projection rather than the whole enrolment: the member's surfaces\n * need to name their gym, show their member id there and open the programme\n * the gym set them. Nothing on a member screen has any use for the invite\n * address the desk recorded, so it does not travel.\n *\n * `assignedWorkoutPlanId` is here because the Workouts tab reads it directly —\n * the plan endpoint it then calls is member-reachable, but the CENTRE's plan\n * list is owner-scoped, so without the id on the profile a member cannot find\n * their own programme at all.\n */\nexport const currentEnrolmentSchema = enrolmentSchema.pick({\n id: true,\n centerId: true,\n centerName: true,\n gymMemberCode: true,\n status: true,\n joinedAt: true,\n assignedWorkoutPlanId: true,\n});\nexport type CurrentEnrolment = z.infer<typeof currentEnrolmentSchema>;\n"]}
|
package/dist/member.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"member.js","sourceRoot":"","sources":["../src/member.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;A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,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,aAAa,EAAE,mBAAmB;IAClC,yEAAyE;IACzE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,SAAS,EAAE,iBAAiB;IAC5B,4EAA4E;IAC5E,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;CACrB,CAAC,CAAC;AAGH;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC/B,CAAC,CAAC;AAGH,gFAAgF;AAEhF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAG3E,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,SAAS,EAAE,cAAc,CAAC,QAAQ,EAAE;CACrC,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,MAAM,EAAE,cAAc,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAGH,wEAAwE;AACxE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC3C,CAAC,CAAC","sourcesContent":["/**\r\n * gymmonk-schema — Member management (owner console)\r\n * ==================================================\r\n * Owner-facing roster + detail projections (User × MemberProfile × Membership)\r\n * and the \"add member\" provisioning payload. Adding a member provisions a real\r\n * central-auth account, so the result carries the login email + temp password.\r\n *\r\n * @module gymmonk-schema/member\r\n */\r\n\r\nimport { z } from 'zod';\r\nimport { gymMemberCodeSchema } from './codes.js';\r\nimport {\r\n isoDateSchema,\r\n isoDateTimeSchema,\r\n objectIdSchema,\r\n optionalTrimmedString,\r\n paginationSchema,\r\n phoneSchema,\r\n priceInrSchema,\r\n} from './common.js';\r\nimport { enrolmentStatusSchema } from './enrolment.js';\r\nimport { emergencyContactSchema, MAX_EMERGENCY_CONTACTS } from './member-profile.js';\r\nimport {\r\n assignMembershipBodySchema,\r\n membershipSchema,\r\n membershipStatusSchema,\r\n} from './membership.js';\r\nimport { planTierSchema } from './membership-plan.js';\r\nimport { addressSchema, bloodGroupSchema, genderSchema } from './shared.js';\r\n\r\n// ─── Segments ────────────────────────────────────────────────────────────────\r\n\r\n/** Attention buckets surfaced on roster cards. */\r\nexport const memberSegmentSchema = z.enum(['expiring', 'new', 'at-risk']);\r\nexport type MemberSegment = z.infer<typeof memberSegmentSchema>;\r\n\r\n// ─── Roster item (list projection) ───────────────────────────────────────────\r\n\r\nexport const memberRosterItemSchema = z.object({\r\n /** The gym record id — always present, even before the member claims. */\r\n enrolmentId: objectIdSchema,\r\n /** Null until claimed; the roster shows an \"Invited\" pill in that state. */\r\n userId: objectIdSchema.nullable(),\r\n recordStatus: enrolmentStatusSchema,\r\n membershipId: objectIdSchema.nullable(),\r\n gymMemberCode: gymMemberCodeSchema,\r\n name: z.string(),\r\n avatarUrl: z.string().nullable(),\r\n verified: z.boolean(),\r\n /**\r\n * Contact details, on the ROSTER row rather than only the detail record.\r\n *\r\n * The card's whole job when someone is overdue is to let the owner chase it\r\n * without leaving the list — call, WhatsApp, email. Those are `tel:` /\r\n * `wa.me` / `mailto:` links, so the row cannot build them without the raw\r\n * values, and fetching the full member just to dial them would be one\r\n * request per card.\r\n *\r\n * Nullable because an invited record may have only one of the two: the gym\r\n * creates it with whatever it has, and the member fills in the rest on claim.\r\n * Phone is RAW 10 digits — `+91` is display-only, never stored.\r\n */\r\n phone: z.string().nullable(),\r\n email: z.email().nullable(),\r\n planName: z.string().nullable(),\r\n tier: planTierSchema.nullable(),\r\n status: membershipStatusSchema.nullable(),\r\n endDate: isoDateSchema.nullable(),\r\n lastVisitAt: isoDateTimeSchema.nullable(),\r\n balanceDueInr: priceInrSchema,\r\n overdueDays: z.number().int().nullable(),\r\n segments: z.array(memberSegmentSchema),\r\n\r\n /**\r\n * When the gym record was created — NOT when the person claimed it. The\r\n * roster's \"Joined Date\" filter groups by how long someone has been a member\r\n * of the gym, which starts at the desk, not at the login.\r\n */\r\n joinedAt: isoDateTimeSchema,\r\n\r\n /**\r\n * Check-ins in the trailing 14 days, used by the roster's attendance filters\r\n * to separate a no-show from an irregular from a regular.\r\n *\r\n * Counted rather than derived from `lastVisitAt`, because the two answer\r\n * different questions: someone who came once yesterday and someone who comes\r\n * daily share a last visit but are not the same member to chase.\r\n */\r\n visits14d: z.number().int().nonnegative(),\r\n\r\n /** Assigned trainer, so the roster can be filtered down to one trainer's people. */\r\n trainerId: objectIdSchema.nullable(),\r\n trainerName: z.string().nullable(),\r\n});\r\n\r\n/** Trailing window the roster's attendance filters and `visits14d` are measured over. */\r\nexport const ATTENDANCE_WINDOW_DAYS = 14;\r\nexport type MemberRosterItem = z.infer<typeof memberRosterItemSchema>;\r\n\r\n/** Header counts for the roster. */\r\nexport const memberListSummarySchema = z.object({\r\n total: z.number().int().nonnegative(),\r\n active: z.number().int().nonnegative(),\r\n expiring: z.number().int().nonnegative(),\r\n inactive: z.number().int().nonnegative(),\r\n});\r\nexport type MemberListSummary = z.infer<typeof memberListSummarySchema>;\r\n\r\n// ─── List query ──────────────────────────────────────────────────────────────\r\n\r\nexport const memberFilterSchema = z.enum(['all', 'active', 'inactive', 'verified']);\r\nexport type MemberFilter = z.infer<typeof memberFilterSchema>;\r\n\r\nexport const memberSortSchema = z.enum(['recent', 'az', 'expiry', 'dues']);\r\nexport type MemberSort = z.infer<typeof memberSortSchema>;\r\n\r\nexport const memberListQuerySchema = paginationSchema.extend({\r\n centerId: objectIdSchema.optional(),\r\n filter: memberFilterSchema.default('all'),\r\n sort: memberSortSchema.default('recent'),\r\n tier: planTierSchema.optional(),\r\n q: optionalTrimmedString(120),\r\n});\r\nexport type MemberListQuery = z.infer<typeof memberListQuerySchema>;\r\n\r\n// ─── Detail projection ───────────────────────────────────────────────────────\r\n\r\n/** The identity slice a projection pulls from the auth `User`. */\r\nexport const memberUserRefSchema = z.object({\r\n /** Null while the record is still `invited` (no central-auth account linked). */\r\n id: objectIdSchema.nullable(),\r\n name: z.string(),\r\n email: z.string(),\r\n phone: z.string().nullable(),\r\n avatarUrl: z.string().nullable(),\r\n verified: z.boolean(),\r\n});\r\nexport type MemberUserRef = z.infer<typeof memberUserRefSchema>;\r\n\r\nexport const memberDetailSchema = z.object({\r\n enrolmentId: objectIdSchema,\r\n recordStatus: enrolmentStatusSchema,\r\n /**\r\n * Identity from central auth once claimed. Before that the gym still knows the\r\n * person (name / contact captured at the desk), so this carries the invited\r\n * details with `id: null`.\r\n */\r\n user: memberUserRefSchema,\r\n gymMemberCode: gymMemberCodeSchema,\r\n gender: genderSchema.nullable(),\r\n dob: isoDateSchema.nullable(),\r\n bloodGroup: bloodGroupSchema.nullable(),\r\n address: addressSchema.nullable(),\r\n emergencyContacts: z.array(emergencyContactSchema),\r\n /**\r\n * Last four digits of the member's Aadhaar, when one was recorded at the desk.\r\n * The full number is never stored (see `member-profile`), so this is all the\r\n * owner console can ever show — enough to match against the physical card the\r\n * member presents, useless to anyone who sees the screen.\r\n */\r\n aadhaarLast4: z.string().nullable(),\r\n /**\r\n * The scanned ID the desk took, if any. Carried on the detail projection so\r\n * the owner's edit form can round-trip it: a form that cannot see a stored\r\n * value sends back a blank one, and blank means \"clear it\".\r\n */\r\n idProofUrl: z.string().nullable(),\r\n joinedAt: isoDateTimeSchema,\r\n lastVisitAt: isoDateTimeSchema.nullable(),\r\n assignedWorkoutPlanId: objectIdSchema.nullable(),\r\n assignedTrainerId: objectIdSchema.nullable(),\r\n /**\r\n * The member's current membership, in FULL rather than by id.\r\n *\r\n * The profile screen shows the plan name, its billing cycle, the lifecycle\r\n * status pill and the expiry date all at once, and every one of those lives\r\n * here. Sending only the id forced the owner console to re-query the roster\r\n * for the same member just to read the plan columns back, and to match the\r\n * plan by NAME to find its perk icons — both of which this removes.\r\n */\r\n membership: membershipSchema.nullable(),\r\n /**\r\n * Still owed on the current term: its price less what has been recorded as\r\n * collected. Zero when settled, when the membership was cancelled, or when\r\n * there is no membership at all. Same definition as the roster's column, so\r\n * the profile and the list can never disagree about who owes money.\r\n */\r\n balanceDueInr: z.number().int().nonnegative(),\r\n});\r\nexport type MemberDetail = z.infer<typeof memberDetailSchema>;\r\n\r\n// ─── Add member (provisioning) ───────────────────────────────────────────────\r\n\r\nexport const createMemberBodySchema = z.object({\r\n firstName: z.string().trim().min(1, 'First name is required').max(80),\r\n lastName: optionalTrimmedString(80),\r\n email: z.email('A valid email is required'),\r\n phone: phoneSchema,\r\n gender: genderSchema,\r\n dob: isoDateSchema.optional(),\r\n bloodGroup: bloodGroupSchema.optional(),\r\n address: addressSchema.optional(),\r\n emergencyContacts: z.array(emergencyContactSchema).max(MAX_EMERGENCY_CONTACTS).default([]),\r\n idProofUrl: optionalTrimmedString(2000),\r\n avatarUrl: optionalTrimmedString(2000),\r\n assignedTrainerId: objectIdSchema.optional(),\r\n /** Optionally assign a plan in the same step. */\r\n initialPlan: assignMembershipBodySchema.optional(),\r\n});\r\nexport type CreateMemberBody = z.infer<typeof createMemberBodySchema>;\r\n\r\n/**\r\n * Edit a member's record from the owner console.\r\n *\r\n * Every field is optional — the console sends what the form holds, and a field\r\n * left out is left alone.\r\n *\r\n * ## What the gym may and may not change\r\n * `firstName` / `lastName` / `email` / `phone` are the INVITE details, and the\r\n * server accepts them only while the record is unclaimed. Once the member has\r\n * linked their central-auth account, that account is the source of truth for\r\n * their identity and is shared with the other products — a gym must not be able\r\n * to rewrite someone's name or email out from under them. The server ignores\r\n * those four on a claimed record rather than failing the whole request, so an\r\n * owner correcting a blood group is never blocked by a name they cannot change.\r\n *\r\n * Nullable fields (`dob`, `bloodGroup`, `address`, `assignedTrainerId`) accept\r\n * `null` to CLEAR a value, which `undefined` cannot express.\r\n */\r\nexport const updateMemberBodySchema = createMemberBodySchema\r\n .omit({\r\n initialPlan: true,\r\n dob: true,\r\n bloodGroup: true,\r\n address: true,\r\n assignedTrainerId: true,\r\n })\r\n .partial()\r\n .extend({\r\n dob: isoDateSchema.nullish(),\r\n bloodGroup: bloodGroupSchema.nullish(),\r\n address: addressSchema.nullish(),\r\n assignedTrainerId: objectIdSchema.nullish(),\r\n /** Last four digits only — the full number is never stored. */\r\n aadhaarLast4: z\r\n .string()\r\n .trim()\r\n .regex(/^\\d{4}$/, 'Enter the last four digits of the Aadhaar number')\r\n .nullish(),\r\n });\r\nexport type UpdateMemberBody = z.infer<typeof updateMemberBodySchema>;\r\n\r\n// ─── Invite & claim ──────────────────────────────────────────────────────────\r\n\r\n/**\r\n * The invite a gym hands to a new member.\r\n *\r\n * GymMonk never mints credentials for anyone: central auth is the SSOT for\r\n * identity, and an account there is shared across products. So adding a member\r\n * creates a gym record only, plus an unguessable invite code. The member\r\n * registers/logs in themselves through central auth (exactly as in jansathi) and\r\n * then CLAIMS the record. The owner shares `url` over WhatsApp or shows the QR.\r\n */\r\nexport const memberInviteSchema = z.object({\r\n /** Single-use, unguessable. Regenerating an invite invalidates the old one. */\r\n code: z.string(),\r\n /** Absolute claim URL the owner shares (also encoded into the QR). */\r\n url: z.string(),\r\n /** The address the member MUST register with for the claim to succeed. */\r\n email: z.string(),\r\n /** WhatsApp number to share on, when the gym recorded one. */\r\n phone: z.string().nullable(),\r\n expiresAt: isoDateTimeSchema,\r\n});\r\nexport type MemberInvite = z.infer<typeof memberInviteSchema>;\r\n\r\n/** Result of adding a member: the gym record + the invite to hand over. */\r\nexport const provisionResultSchema = z.object({\r\n /** The new member record (NOT a central-auth user — none is created). */\r\n enrolmentId: objectIdSchema,\r\n code: z.string(),\r\n invite: memberInviteSchema,\r\n /**\r\n * The membership created from `initialPlan`, or `null`.\r\n *\r\n * Null means one of two DIFFERENT things, and the caller can tell them apart\r\n * because it knows whether it sent `initialPlan`: no plan was chosen, or the\r\n * chosen plan could not be assigned. Adding a member never fails over the\r\n * second case — the person is on the roster either way — so this is how the\r\n * owner finds out the plan still needs assigning rather than assuming it took.\r\n */\r\n membership: membershipSchema.nullable(),\r\n});\r\nexport type ProvisionResult = z.infer<typeof provisionResultSchema>;\r\n\r\n/**\r\n * What the claim screen shows BEFORE the member authenticates, so they know\r\n * which address to register with. Public (the code is the bearer secret), and\r\n * deliberately minimal — gym name, member code, and the expected email.\r\n */\r\nexport const invitePreviewSchema = z.object({\r\n gymName: z.string(),\r\n gymMemberCode: gymMemberCodeSchema,\r\n /** Shown verbatim: the member must know exactly which address to use. */\r\n email: z.string(),\r\n expiresAt: isoDateTimeSchema,\r\n /** True once claimed / expired, so the screen can explain why it failed. */\r\n claimed: z.boolean(),\r\n expired: z.boolean(),\r\n});\r\nexport type InvitePreview = z.infer<typeof invitePreviewSchema>;\r\n\r\n/**\r\n * Claim an invite as the authenticated caller. The server links the record only\r\n * when the code is valid AND the caller's central-auth email matches the address\r\n * the invite was issued to.\r\n */\r\nexport const claimInviteBodySchema = z.object({\r\n code: z.string().trim().min(1),\r\n});\r\nexport type ClaimInviteBody = z.infer<typeof claimInviteBodySchema>;\r\n\r\n// ─── Mutations ───────────────────────────────────────────────────────────────\r\n\r\nexport const setMemberStatusBodySchema = z.object({ active: z.boolean() });\r\nexport type SetMemberStatusBody = z.infer<typeof setMemberStatusBodySchema>;\r\n\r\nexport const assignTrainerBodySchema = z.object({\r\n trainerId: objectIdSchema.nullable(),\r\n});\r\nexport type AssignTrainerBody = z.infer<typeof assignTrainerBodySchema>;\r\n\r\nexport const assignWorkoutPlanBodySchema = z.object({\r\n planId: objectIdSchema.nullable(),\r\n});\r\nexport type AssignWorkoutPlanBody = z.infer<typeof assignWorkoutPlanBodySchema>;\r\n\r\n/** Remove a member from the gym — echoes the member code to confirm. */\r\nexport const deleteMemberBodySchema = z.object({\r\n confirmationCode: z.string().trim().min(1),\r\n});\r\nexport type DeleteMemberBody = z.infer<typeof deleteMemberBodySchema>;\r\n"]}
|
|
1
|
+
{"version":3,"file":"member.js","sourceRoot":"","sources":["../src/member.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,EACL,0BAA0B,EAC1B,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5E,gFAAgF;AAEhF,kDAAkD;AAClD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;AAG1E,gFAAgF;AAEhF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,yEAAyE;IACzE,WAAW,EAAE,cAAc;IAC3B,4EAA4E;IAC5E,MAAM,EAAE,cAAc,CAAC,QAAQ,EAAE;IACjC,YAAY,EAAE,qBAAqB;IACnC,YAAY,EAAE,cAAc,CAAC,QAAQ,EAAE;IACvC,aAAa,EAAE,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AAE,EAAE,CAAC,CAAC;AAG3E,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,SAAS,EAAE,cAAc,CAAC,QAAQ,EAAE;CACrC,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,MAAM,EAAE,cAAc,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAGH,wEAAwE;AACxE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC3C,CAAC,CAAC","sourcesContent":["/**\n * gymmonk-schema — Member management (owner console)\n * ==================================================\n * Owner-facing roster + detail projections (User × MemberProfile × Membership)\n * and the \"add member\" provisioning payload. Adding a member provisions a real\n * central-auth account, so the result carries the login email + temp password.\n *\n * @module gymmonk-schema/member\n */\n\nimport { z } from 'zod';\nimport { gymMemberCodeSchema } from './codes.js';\nimport {\n isoDateSchema,\n isoDateTimeSchema,\n objectIdSchema,\n optionalTrimmedString,\n paginationSchema,\n phoneSchema,\n priceInrSchema,\n} from './common.js';\nimport { enrolmentStatusSchema } from './enrolment.js';\nimport { emergencyContactSchema, MAX_EMERGENCY_CONTACTS } from './member-profile.js';\nimport {\n assignMembershipBodySchema,\n membershipSchema,\n membershipStatusSchema,\n} from './membership.js';\nimport { planTierSchema } from './membership-plan.js';\nimport { addressSchema, bloodGroupSchema, genderSchema } from './shared.js';\n\n// ─── Segments ────────────────────────────────────────────────────────────────\n\n/** Attention buckets surfaced on roster cards. */\nexport const memberSegmentSchema = z.enum(['expiring', 'new', 'at-risk']);\nexport type MemberSegment = z.infer<typeof memberSegmentSchema>;\n\n// ─── Roster item (list projection) ───────────────────────────────────────────\n\nexport const memberRosterItemSchema = z.object({\n /** The gym record id — always present, even before the member claims. */\n enrolmentId: objectIdSchema,\n /** Null until claimed; the roster shows an \"Invited\" pill in that state. */\n userId: objectIdSchema.nullable(),\n recordStatus: enrolmentStatusSchema,\n membershipId: objectIdSchema.nullable(),\n gymMemberCode: gymMemberCodeSchema,\n name: z.string(),\n avatarUrl: z.string().nullable(),\n verified: z.boolean(),\n /**\n * Contact details, on the ROSTER row rather than only the detail record.\n *\n * The card's whole job when someone is overdue is to let the owner chase it\n * without leaving the list — call, WhatsApp, email. Those are `tel:` /\n * `wa.me` / `mailto:` links, so the row cannot build them without the raw\n * values, and fetching the full member just to dial them would be one\n * request per card.\n *\n * Nullable because an invited record may have only one of the two: the gym\n * creates it with whatever it has, and the member fills in the rest on claim.\n * Phone is RAW 10 digits — `+91` is display-only, never stored.\n */\n phone: z.string().nullable(),\n email: z.email().nullable(),\n planName: z.string().nullable(),\n tier: planTierSchema.nullable(),\n status: membershipStatusSchema.nullable(),\n endDate: isoDateSchema.nullable(),\n lastVisitAt: isoDateTimeSchema.nullable(),\n balanceDueInr: priceInrSchema,\n overdueDays: z.number().int().nullable(),\n segments: z.array(memberSegmentSchema),\n\n /**\n * When the gym record was created — NOT when the person claimed it. The\n * roster's \"Joined Date\" filter groups by how long someone has been a member\n * of the gym, which starts at the desk, not at the login.\n */\n joinedAt: isoDateTimeSchema,\n\n /**\n * Check-ins in the trailing 14 days, used by the roster's attendance filters\n * to separate a no-show from an irregular from a regular.\n *\n * Counted rather than derived from `lastVisitAt`, because the two answer\n * different questions: someone who came once yesterday and someone who comes\n * daily share a last visit but are not the same member to chase.\n */\n visits14d: z.number().int().nonnegative(),\n\n /** Assigned trainer, so the roster can be filtered down to one trainer's people. */\n trainerId: objectIdSchema.nullable(),\n trainerName: z.string().nullable(),\n});\n\n/** Trailing window the roster's attendance filters and `visits14d` are measured over. */\nexport const ATTENDANCE_WINDOW_DAYS = 14;\nexport type MemberRosterItem = z.infer<typeof memberRosterItemSchema>;\n\n/** Header counts for the roster. */\nexport const memberListSummarySchema = z.object({\n total: z.number().int().nonnegative(),\n active: z.number().int().nonnegative(),\n expiring: z.number().int().nonnegative(),\n inactive: z.number().int().nonnegative(),\n});\nexport type MemberListSummary = z.infer<typeof memberListSummarySchema>;\n\n// ─── List query ──────────────────────────────────────────────────────────────\n\nexport const memberFilterSchema = z.enum(['all', 'active', 'inactive', 'verified']);\nexport type MemberFilter = z.infer<typeof memberFilterSchema>;\n\nexport const memberSortSchema = z.enum(['recent', 'az', 'expiry', 'dues']);\nexport type MemberSort = z.infer<typeof memberSortSchema>;\n\nexport const memberListQuerySchema = paginationSchema.extend({\n centerId: objectIdSchema.optional(),\n filter: memberFilterSchema.default('all'),\n sort: memberSortSchema.default('recent'),\n tier: planTierSchema.optional(),\n q: optionalTrimmedString(120),\n});\nexport type MemberListQuery = z.infer<typeof memberListQuerySchema>;\n\n// ─── Detail projection ───────────────────────────────────────────────────────\n\n/** The identity slice a projection pulls from the auth `User`. */\nexport const memberUserRefSchema = z.object({\n /** Null while the record is still `invited` (no central-auth account linked). */\n id: objectIdSchema.nullable(),\n name: z.string(),\n email: z.string(),\n phone: z.string().nullable(),\n avatarUrl: z.string().nullable(),\n verified: z.boolean(),\n});\nexport type MemberUserRef = z.infer<typeof memberUserRefSchema>;\n\nexport const memberDetailSchema = z.object({\n enrolmentId: objectIdSchema,\n recordStatus: enrolmentStatusSchema,\n /**\n * Identity from central auth once claimed. Before that the gym still knows the\n * person (name / contact captured at the desk), so this carries the invited\n * details with `id: null`.\n */\n user: memberUserRefSchema,\n gymMemberCode: gymMemberCodeSchema,\n gender: genderSchema.nullable(),\n dob: isoDateSchema.nullable(),\n bloodGroup: bloodGroupSchema.nullable(),\n address: addressSchema.nullable(),\n emergencyContacts: z.array(emergencyContactSchema),\n /**\n * Last four digits of the member's Aadhaar, when one was recorded at the desk.\n * The full number is never stored (see `member-profile`), so this is all the\n * owner console can ever show — enough to match against the physical card the\n * member presents, useless to anyone who sees the screen.\n */\n aadhaarLast4: z.string().nullable(),\n /**\n * The scanned ID the desk took, if any. Carried on the detail projection so\n * the owner's edit form can round-trip it: a form that cannot see a stored\n * value sends back a blank one, and blank means \"clear it\".\n */\n idProofUrl: z.string().nullable(),\n joinedAt: isoDateTimeSchema,\n lastVisitAt: isoDateTimeSchema.nullable(),\n assignedWorkoutPlanId: objectIdSchema.nullable(),\n assignedTrainerId: objectIdSchema.nullable(),\n /**\n * The member's current membership, in FULL rather than by id.\n *\n * The profile screen shows the plan name, its billing cycle, the lifecycle\n * status pill and the expiry date all at once, and every one of those lives\n * here. Sending only the id forced the owner console to re-query the roster\n * for the same member just to read the plan columns back, and to match the\n * plan by NAME to find its perk icons — both of which this removes.\n */\n membership: membershipSchema.nullable(),\n /**\n * Still owed on the current term: its price less what has been recorded as\n * collected. Zero when settled, when the membership was cancelled, or when\n * there is no membership at all. Same definition as the roster's column, so\n * the profile and the list can never disagree about who owes money.\n */\n balanceDueInr: z.number().int().nonnegative(),\n});\nexport type MemberDetail = z.infer<typeof memberDetailSchema>;\n\n// ─── Add member (provisioning) ───────────────────────────────────────────────\n\nexport const createMemberBodySchema = z.object({\n firstName: z.string().trim().min(1, 'First name is required').max(80),\n lastName: optionalTrimmedString(80),\n email: z.email('A valid email is required'),\n phone: phoneSchema,\n gender: genderSchema,\n dob: isoDateSchema.optional(),\n bloodGroup: bloodGroupSchema.optional(),\n address: addressSchema.optional(),\n emergencyContacts: z.array(emergencyContactSchema).max(MAX_EMERGENCY_CONTACTS).default([]),\n idProofUrl: optionalTrimmedString(2000),\n avatarUrl: optionalTrimmedString(2000),\n assignedTrainerId: objectIdSchema.optional(),\n /** Optionally assign a plan in the same step. */\n initialPlan: assignMembershipBodySchema.optional(),\n});\nexport type CreateMemberBody = z.infer<typeof createMemberBodySchema>;\n\n/**\n * Edit a member's record from the owner console.\n *\n * Every field is optional — the console sends what the form holds, and a field\n * left out is left alone.\n *\n * ## What the gym may and may not change\n * `firstName` / `lastName` / `email` / `phone` are the INVITE details, and the\n * server accepts them only while the record is unclaimed. Once the member has\n * linked their central-auth account, that account is the source of truth for\n * their identity and is shared with the other products — a gym must not be able\n * to rewrite someone's name or email out from under them. The server ignores\n * those four on a claimed record rather than failing the whole request, so an\n * owner correcting a blood group is never blocked by a name they cannot change.\n *\n * Nullable fields (`dob`, `bloodGroup`, `address`, `assignedTrainerId`) accept\n * `null` to CLEAR a value, which `undefined` cannot express.\n */\nexport const updateMemberBodySchema = createMemberBodySchema\n .omit({\n initialPlan: true,\n dob: true,\n bloodGroup: true,\n address: true,\n assignedTrainerId: true,\n })\n .partial()\n .extend({\n dob: isoDateSchema.nullish(),\n bloodGroup: bloodGroupSchema.nullish(),\n address: addressSchema.nullish(),\n assignedTrainerId: objectIdSchema.nullish(),\n /** Last four digits only — the full number is never stored. */\n aadhaarLast4: z\n .string()\n .trim()\n .regex(/^\\d{4}$/, 'Enter the last four digits of the Aadhaar number')\n .nullish(),\n });\nexport type UpdateMemberBody = z.infer<typeof updateMemberBodySchema>;\n\n// ─── Invite & claim ──────────────────────────────────────────────────────────\n\n/**\n * The invite a gym hands to a new member.\n *\n * GymMonk never mints credentials for anyone: central auth is the SSOT for\n * identity, and an account there is shared across products. So adding a member\n * creates a gym record only, plus an unguessable invite code. The member\n * registers/logs in themselves through central auth (exactly as in jansathi) and\n * then CLAIMS the record. The owner shares `url` over WhatsApp or shows the QR.\n */\nexport const memberInviteSchema = z.object({\n /** Single-use, unguessable. Regenerating an invite invalidates the old one. */\n code: z.string(),\n /** Absolute claim URL the owner shares (also encoded into the QR). */\n url: z.string(),\n /** The address the member MUST register with for the claim to succeed. */\n email: z.string(),\n /** WhatsApp number to share on, when the gym recorded one. */\n phone: z.string().nullable(),\n expiresAt: isoDateTimeSchema,\n});\nexport type MemberInvite = z.infer<typeof memberInviteSchema>;\n\n/** Result of adding a member: the gym record + the invite to hand over. */\nexport const provisionResultSchema = z.object({\n /** The new member record (NOT a central-auth user — none is created). */\n enrolmentId: objectIdSchema,\n code: z.string(),\n invite: memberInviteSchema,\n /**\n * The membership created from `initialPlan`, or `null`.\n *\n * Null means one of two DIFFERENT things, and the caller can tell them apart\n * because it knows whether it sent `initialPlan`: no plan was chosen, or the\n * chosen plan could not be assigned. Adding a member never fails over the\n * second case — the person is on the roster either way — so this is how the\n * owner finds out the plan still needs assigning rather than assuming it took.\n */\n membership: membershipSchema.nullable(),\n});\nexport type ProvisionResult = z.infer<typeof provisionResultSchema>;\n\n/**\n * What the claim screen shows BEFORE the member authenticates, so they know\n * which address to register with. Public (the code is the bearer secret), and\n * deliberately minimal — gym name, member code, and the expected email.\n */\nexport const invitePreviewSchema = z.object({\n gymName: z.string(),\n gymMemberCode: gymMemberCodeSchema,\n /** Shown verbatim: the member must know exactly which address to use. */\n email: z.string(),\n expiresAt: isoDateTimeSchema,\n /** True once claimed / expired, so the screen can explain why it failed. */\n claimed: z.boolean(),\n expired: z.boolean(),\n});\nexport type InvitePreview = z.infer<typeof invitePreviewSchema>;\n\n/**\n * Claim an invite as the authenticated caller. The server links the record only\n * when the code is valid AND the caller's central-auth email matches the address\n * the invite was issued to.\n */\nexport const claimInviteBodySchema = z.object({\n code: z.string().trim().min(1),\n});\nexport type ClaimInviteBody = z.infer<typeof claimInviteBodySchema>;\n\n// ─── Mutations ───────────────────────────────────────────────────────────────\n\nexport const setMemberStatusBodySchema = z.object({ active: z.boolean() });\nexport type SetMemberStatusBody = z.infer<typeof setMemberStatusBodySchema>;\n\nexport const assignTrainerBodySchema = z.object({\n trainerId: objectIdSchema.nullable(),\n});\nexport type AssignTrainerBody = z.infer<typeof assignTrainerBodySchema>;\n\nexport const assignWorkoutPlanBodySchema = z.object({\n planId: objectIdSchema.nullable(),\n});\nexport type AssignWorkoutPlanBody = z.infer<typeof assignWorkoutPlanBodySchema>;\n\n/** Remove a member from the gym — echoes the member code to confirm. */\nexport const deleteMemberBodySchema = z.object({\n confirmationCode: z.string().trim().min(1),\n});\nexport type DeleteMemberBody = z.infer<typeof deleteMemberBodySchema>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gymmonk-schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "Shared Zod schemas, enums and domain types for GymMonk (fitness SaaS) — single source of truth (SSOT) consumed by gymmonk-backend and gymmonk-web-client.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|