|
@@ -1,5 +1,5 @@
|
|
|
// db
|
|
|
-import { selPool } from "#db";
|
|
|
+import { selPool, updPool } from "#db";
|
|
|
import { DbSchema } from "#db-schema";
|
|
|
import { sql } from "slonik";
|
|
|
|
|
@@ -65,6 +65,53 @@ class ClientUsersController {
|
|
|
},
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ async patchUserEventData(
|
|
|
+ req: Request,
|
|
|
+ res: Response,
|
|
|
+ // next: NextFunction
|
|
|
+ ) {
|
|
|
+ const user = sessionService.getUserFromReq(req);
|
|
|
+ const userData = api.client.users.PATCH_UserEventData.req.userData.parse(
|
|
|
+ req.body,
|
|
|
+ );
|
|
|
+
|
|
|
+ const userId = user.userId;
|
|
|
+ // TODO: добавить валидацию
|
|
|
+ updPool.transaction(async (t) => {
|
|
|
+ for (const field of userData) {
|
|
|
+ const fieldDefinitionId = field.fieldDefinitionId;
|
|
|
+ const value = field.value;
|
|
|
+
|
|
|
+ t.query(sql.unsafe`
|
|
|
+ delete from
|
|
|
+ ev.user_event_field_values v
|
|
|
+ where
|
|
|
+ v.field_definition_id = ${fieldDefinitionId}
|
|
|
+ and
|
|
|
+ v.user_id = ${userId};
|
|
|
+
|
|
|
+ insert
|
|
|
+ into
|
|
|
+ ev.user_event_field_values (
|
|
|
+ user_id,
|
|
|
+ field_definition_id,
|
|
|
+ value)
|
|
|
+ values (
|
|
|
+ ${userId},
|
|
|
+ ${fieldDefinitionId},
|
|
|
+ ${value}
|
|
|
+ );
|
|
|
+ `);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ RouterUtils.validAndSendResponse(
|
|
|
+ api.client.users.PATCH_UserEventData.res,
|
|
|
+ res,
|
|
|
+ { code: "success" },
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export const clientUsersController = new ClientUsersController();
|