|
@@ -27,33 +27,36 @@ class ClientUsersController {
|
|
const userData = await selPool.any(sql.type(
|
|
const userData = await selPool.any(sql.type(
|
|
z.object({
|
|
z.object({
|
|
fieldDefinitionId: DbSchema.cf.customFieldDefinitions.fieldDefinitionId,
|
|
fieldDefinitionId: DbSchema.cf.customFieldDefinitions.fieldDefinitionId,
|
|
|
|
+ userEfId: DbSchema.ev.userEventFields.userEfId,
|
|
code: DbSchema.cf.customFieldDefinitions.code,
|
|
code: DbSchema.cf.customFieldDefinitions.code,
|
|
fieldTypeCode: DbSchema.cf.fieldTypes.code,
|
|
fieldTypeCode: DbSchema.cf.fieldTypes.code,
|
|
title: DbSchema.cf.customFieldDefinitions.title,
|
|
title: DbSchema.cf.customFieldDefinitions.title,
|
|
mask: DbSchema.cf.customFieldDefinitions.mask,
|
|
mask: DbSchema.cf.customFieldDefinitions.mask,
|
|
options: DbSchema.cf.customFieldDefinitions.options,
|
|
options: DbSchema.cf.customFieldDefinitions.options,
|
|
validators: z.array(Validator),
|
|
validators: z.array(Validator),
|
|
- userValue: DbSchema.ev.userEventFieldValues.value,
|
|
|
|
|
|
+ value: DbSchema.ev.userEventFieldValues.value,
|
|
}),
|
|
}),
|
|
)`
|
|
)`
|
|
select
|
|
select
|
|
uef.field_definition_id as "fieldDefinitionId",
|
|
uef.field_definition_id as "fieldDefinitionId",
|
|
|
|
+ uef.user_ef_id as "userEfId",
|
|
cfwv.code,
|
|
cfwv.code,
|
|
cfwv.field_type_code as "fieldTypeCode",
|
|
cfwv.field_type_code as "fieldTypeCode",
|
|
- cfwv.title,
|
|
|
|
|
|
+ COALESCE(uef.field_title_override, cfwv.title) as "title",
|
|
cfwv.mask,
|
|
cfwv.mask,
|
|
cfwv."options",
|
|
cfwv."options",
|
|
cfwv.validators,
|
|
cfwv.validators,
|
|
- uefv.value as "userValue"
|
|
|
|
|
|
+ uefv.value as "value"
|
|
from
|
|
from
|
|
ev.user_event_fields uef
|
|
ev.user_event_fields uef
|
|
join cf.custom_fields_with_validators cfwv on
|
|
join cf.custom_fields_with_validators cfwv on
|
|
uef.field_definition_id = cfwv.field_definition_id
|
|
uef.field_definition_id = cfwv.field_definition_id
|
|
left join ev.user_event_field_values uefv on
|
|
left join ev.user_event_field_values uefv on
|
|
- uef.field_definition_id = uefv.field_definition_id
|
|
|
|
|
|
+ uef.user_ef_id = uefv.user_ef_id
|
|
and uefv.user_id = ${user.userId}
|
|
and uefv.user_id = ${user.userId}
|
|
where
|
|
where
|
|
uef.event_id = ${event.eventId}
|
|
uef.event_id = ${event.eventId}
|
|
|
|
+
|
|
`);
|
|
`);
|
|
|
|
|
|
RouterUtils.validAndSendResponse(
|
|
RouterUtils.validAndSendResponse(
|
|
@@ -72,7 +75,7 @@ class ClientUsersController {
|
|
// next: NextFunction
|
|
// next: NextFunction
|
|
) {
|
|
) {
|
|
const user = sessionService.getUserFromReq(req);
|
|
const user = sessionService.getUserFromReq(req);
|
|
- const userData = api.client.users.PATCH_UserEventData.req.userData.parse(
|
|
|
|
|
|
+ const { userData } = api.client.users.PATCH_UserEventData.req.parse(
|
|
req.body,
|
|
req.body,
|
|
);
|
|
);
|
|
|
|
|
|
@@ -80,26 +83,28 @@ class ClientUsersController {
|
|
// TODO: добавить валидацию
|
|
// TODO: добавить валидацию
|
|
updPool.transaction(async (t) => {
|
|
updPool.transaction(async (t) => {
|
|
for (const field of userData) {
|
|
for (const field of userData) {
|
|
- const fieldDefinitionId = field.fieldDefinitionId;
|
|
|
|
|
|
+ const userEfId = field.userEfId;
|
|
const value = field.value;
|
|
const value = field.value;
|
|
|
|
|
|
t.query(sql.unsafe`
|
|
t.query(sql.unsafe`
|
|
delete from
|
|
delete from
|
|
ev.user_event_field_values v
|
|
ev.user_event_field_values v
|
|
where
|
|
where
|
|
- v.field_definition_id = ${fieldDefinitionId}
|
|
|
|
|
|
+ v.user_ef_id = ${userEfId}
|
|
and
|
|
and
|
|
v.user_id = ${userId};
|
|
v.user_id = ${userId};
|
|
|
|
+ `);
|
|
|
|
|
|
|
|
+ t.query(sql.unsafe`
|
|
insert
|
|
insert
|
|
into
|
|
into
|
|
ev.user_event_field_values (
|
|
ev.user_event_field_values (
|
|
user_id,
|
|
user_id,
|
|
- field_definition_id,
|
|
|
|
|
|
+ user_ef_id,
|
|
value)
|
|
value)
|
|
values (
|
|
values (
|
|
${userId},
|
|
${userId},
|
|
- ${fieldDefinitionId},
|
|
|
|
|
|
+ ${userEfId},
|
|
${value}
|
|
${value}
|
|
);
|
|
);
|
|
`);
|
|
`);
|