feat(F-105): completed feature
This commit is contained in:
@@ -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(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user