|
@@ -0,0 +1,70 @@
|
|
|
+// db
|
|
|
+import { selPool } from "#db";
|
|
|
+import { DbSchema } from "#db-schema";
|
|
|
+import { sql } from "slonik";
|
|
|
+
|
|
|
+// api
|
|
|
+import { api } from "#api";
|
|
|
+
|
|
|
+// other
|
|
|
+import { z } from "zod";
|
|
|
+
|
|
|
+import { RouterUtils } from "#utils/router-utils.js";
|
|
|
+
|
|
|
+import { Request, Response } from "express";
|
|
|
+import sessionService from "#modules/users/auth/services/session-service.js";
|
|
|
+import { Validator } from "#api/v_0.1.0/types/pe-types.js";
|
|
|
+
|
|
|
+class ClientUsersController {
|
|
|
+ async getUserEventData(
|
|
|
+ req: Request,
|
|
|
+ res: Response,
|
|
|
+ // next: NextFunction
|
|
|
+ ) {
|
|
|
+ const event = await sessionService.getCurrentEventFromReq(req);
|
|
|
+ const user = sessionService.getUserFromReq(req);
|
|
|
+
|
|
|
+ const userData = await selPool.any(sql.type(
|
|
|
+ z.object({
|
|
|
+ fieldDefinitionId: DbSchema.cf.customFieldDefinitions.fieldDefinitionId,
|
|
|
+ code: DbSchema.cf.customFieldDefinitions.code,
|
|
|
+ fieldTypeCode: DbSchema.cf.fieldTypes.code,
|
|
|
+ title: DbSchema.cf.customFieldDefinitions.title,
|
|
|
+ mask: DbSchema.cf.customFieldDefinitions.mask,
|
|
|
+ options: DbSchema.cf.customFieldDefinitions.options,
|
|
|
+ validators: z.array(Validator),
|
|
|
+ userValue: DbSchema.ev.userEventFieldValues.value,
|
|
|
+ }),
|
|
|
+ )`
|
|
|
+ select
|
|
|
+ uef.field_definition_id as "fieldDefinitionId",
|
|
|
+ cfwv.code,
|
|
|
+ cfwv.field_type_code as "fieldTypeCode",
|
|
|
+ cfwv.title,
|
|
|
+ cfwv.mask,
|
|
|
+ cfwv."options",
|
|
|
+ cfwv.validators,
|
|
|
+ uefv.value as "userValue"
|
|
|
+ from
|
|
|
+ ev.user_event_fields uef
|
|
|
+ join cf.custom_fields_with_validators cfwv on
|
|
|
+ uef.field_definition_id = cfwv.field_definition_id
|
|
|
+ left join ev.user_event_field_values uefv on
|
|
|
+ uef.field_definition_id = uefv.field_definition_id
|
|
|
+ and uefv.user_id = ${user.userId}
|
|
|
+ where
|
|
|
+ uef.event_id = ${event.eventId}
|
|
|
+ `);
|
|
|
+
|
|
|
+ RouterUtils.validAndSendResponse(
|
|
|
+ api.client.users.GET_UserEventData.res,
|
|
|
+ res,
|
|
|
+ {
|
|
|
+ code: "success",
|
|
|
+ userData: [...userData],
|
|
|
+ },
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export const clientUsersController = new ClientUsersController();
|