feat(F-105): completed feature

This commit is contained in:
chattie
2026-08-21 08:06:31 +02:00
parent 9b42c506f3
commit 5458789634
13 changed files with 247 additions and 49 deletions

View File

@@ -31,14 +31,25 @@ export interface UsersRoutesDeps {
const uuidParamSchema = z.object({ id: z.uuid() });
const addressIdParamSchema = z.object({ id: z.uuid(), addressId: z.uuid() });
const preferencesSchema = z
.object({
orderUpdates: z.boolean().optional(),
newsletter: z.boolean().optional(),
promos: z.boolean().optional(),
})
.strict();
const profilePatchSchema = z
.object({
displayName: z.string().min(1).max(200).optional(),
phone: z.string().min(1).max(50).optional(),
preferences: preferencesSchema.optional(),
})
.refine((value) => value.displayName !== undefined || value.phone !== undefined, {
message: 'At least one of displayName or phone is required',
});
.refine(
(value) =>
value.displayName !== undefined || value.phone !== undefined || value.preferences !== undefined,
{ message: 'At least one of displayName, phone or preferences is required' },
);
const newAddressSchema = z.object({
label: z.string().max(100).optional().nullable(),
@@ -115,7 +126,8 @@ export async function registerUsersRoutes(
if (!customer) {
throw new AppError(404, 'NOT_FOUND', 'Customer not found');
}
return reply.send(serializeCustomer(customer));
const profile = await profiles.findByUserId(id);
return reply.send({ ...serializeCustomer(customer), preferences: profile?.preferences ?? undefined });
});
const patchUserSchema: FastifySchema = {
@@ -240,6 +252,7 @@ function serializeProfile(profile: Profile) {
userId: profile.userId,
displayName: profile.displayName,
phone: profile.phone,
preferences: profile.preferences,
createdAt: profile.createdAt.toISOString(),
updatedAt: profile.updatedAt.toISOString(),
};