|
@@ -61,7 +61,6 @@ class ClientActivitiesController {
|
|
|
eventInstId: DbSchema.act.activities.eventInstId,
|
|
|
categoryId: DbSchema.act.activities.categoryId,
|
|
|
categoryCode: DbSchema.act.activityCategories.code,
|
|
|
- blockId: DbSchema.act.activities.blockId,
|
|
|
validators: z.array(apiTypes.activities.ActValidator),
|
|
|
peTypes: z.array(
|
|
|
z.object({
|
|
@@ -70,6 +69,7 @@ class ClientActivitiesController {
|
|
|
name: DbSchema.act.peTypes.name,
|
|
|
}),
|
|
|
),
|
|
|
+ isUserReg: DbSchema.act.activities.isUserReg,
|
|
|
}),
|
|
|
)`
|
|
|
select
|
|
@@ -79,9 +79,9 @@ class ClientActivitiesController {
|
|
|
a.event_inst_id "eventInstId",
|
|
|
a.category_id "categoryId",
|
|
|
a.category_code "categoryCode",
|
|
|
- a.block_id "blockId",
|
|
|
a.validators,
|
|
|
- a.pe_types "peTypes"
|
|
|
+ a.pe_types "peTypes",
|
|
|
+ a.is_user_reg "isUserReg"
|
|
|
from
|
|
|
act.act_with_validators a
|
|
|
where
|
|
@@ -142,7 +142,6 @@ class ClientActivitiesController {
|
|
|
eventInstId: DbSchema.act.activities.eventInstId,
|
|
|
categoryId: DbSchema.act.activities.categoryId,
|
|
|
categoryCode: DbSchema.act.activityCategories.code,
|
|
|
- blockId: DbSchema.act.activities.blockId,
|
|
|
validators: z.array(apiTypes.activities.ActValidator),
|
|
|
peTypes: z.array(
|
|
|
z.object({
|
|
@@ -151,6 +150,7 @@ class ClientActivitiesController {
|
|
|
name: DbSchema.act.peTypes.name,
|
|
|
}),
|
|
|
),
|
|
|
+ isUserReg: DbSchema.act.activities.isUserReg,
|
|
|
}),
|
|
|
)`
|
|
|
select
|
|
@@ -160,9 +160,9 @@ class ClientActivitiesController {
|
|
|
a.event_inst_id "eventInstId",
|
|
|
a.category_id "categoryId",
|
|
|
a.category_code "categoryCode",
|
|
|
- a.block_id "blockId",
|
|
|
a.validators,
|
|
|
- a.pe_types "peTypes"
|
|
|
+ a.pe_types "peTypes",
|
|
|
+ a.is_user_reg "isUserReg"
|
|
|
from
|
|
|
act.act_with_validators a
|
|
|
where
|
|
@@ -219,6 +219,7 @@ class ClientActivitiesController {
|
|
|
fields: z.array(
|
|
|
CustomFieldWithUserCopyValue.extend({ arffId: z.string() }),
|
|
|
),
|
|
|
+ isUserReg: DbSchema.act.activities.isUserReg,
|
|
|
}),
|
|
|
)`
|
|
|
select
|
|
@@ -230,7 +231,8 @@ class ClientActivitiesController {
|
|
|
a.category_code "categoryCode",
|
|
|
a.validators,
|
|
|
a.pe_types "peTypes",
|
|
|
- coalesce(f.fields, '[]'::jsonb) "fields"
|
|
|
+ coalesce(f.fields, '[]'::jsonb) "fields",
|
|
|
+ a.is_user_reg "isUserReg"
|
|
|
from
|
|
|
act.act_with_validators a
|
|
|
left join lateral (
|
|
@@ -292,10 +294,7 @@ class ClientActivitiesController {
|
|
|
|
|
|
const files = req.files;
|
|
|
|
|
|
- // проверка доступа
|
|
|
const user = sessionService.getUserFromReq(req);
|
|
|
- const isOwner = await cPeService.checkPeOwner(user.userId, peId);
|
|
|
- if (!isOwner) throw ApiError.ForbiddenError();
|
|
|
|
|
|
const actRegData = await selPool.maybeOne(sql.type(
|
|
|
z.object({
|
|
@@ -316,6 +315,7 @@ class ClientActivitiesController {
|
|
|
fields: z.array(
|
|
|
CustomFieldWithValidators.extend({ arffId: z.string() }),
|
|
|
),
|
|
|
+ isUserReg: DbSchema.act.activities.isUserReg,
|
|
|
}),
|
|
|
)`
|
|
|
select
|
|
@@ -327,7 +327,8 @@ class ClientActivitiesController {
|
|
|
a.category_code "categoryCode",
|
|
|
a.validators,
|
|
|
a.pe_types "peTypes",
|
|
|
- coalesce(f.fields, '[]'::jsonb) "fields"
|
|
|
+ coalesce(f.fields, '[]'::jsonb) "fields",
|
|
|
+ a.is_user_reg "isUserReg"
|
|
|
from
|
|
|
act.act_with_validators a
|
|
|
left join lateral (
|
|
@@ -357,6 +358,18 @@ class ClientActivitiesController {
|
|
|
"actRegDataNotFound",
|
|
|
"Данные для регистрации на мероприятии не найдены",
|
|
|
);
|
|
|
+ //
|
|
|
+
|
|
|
+ // проверка доступа
|
|
|
+ if (!actRegData.isUserReg) {
|
|
|
+ if (!peId)
|
|
|
+ throw ApiError.BadRequest(
|
|
|
+ "peIdNotFound",
|
|
|
+ "ID сущности участия не передан",
|
|
|
+ );
|
|
|
+ const isOwner = await cPeService.checkPeOwner(user.userId, peId);
|
|
|
+ if (!isOwner) throw ApiError.ForbiddenError();
|
|
|
+ }
|
|
|
|
|
|
//
|
|
|
// -- ВАЛИДАЦИЯ --
|
|
@@ -379,21 +392,28 @@ class ClientActivitiesController {
|
|
|
);
|
|
|
//
|
|
|
// валидация pe
|
|
|
- const pe = await cPeService.getPeWithValues(peId);
|
|
|
- const members = await cPeService.getMembers(peId);
|
|
|
- if (!pe)
|
|
|
- throw ApiError.BadRequest("peNotFound", "Сущность участия не найдена");
|
|
|
-
|
|
|
- const fullPe = {
|
|
|
- ...pe,
|
|
|
- members: [...members],
|
|
|
- };
|
|
|
- const validatedPe = validatePeForAct(actRegData, fullPe);
|
|
|
- if (!validatedPe.isValid)
|
|
|
- throw ApiError.BadRequest(
|
|
|
- "peValidatorFailed",
|
|
|
- validatedPe.messages.join(", "),
|
|
|
- );
|
|
|
+ if (!actRegData.isUserReg) {
|
|
|
+ if (!peId)
|
|
|
+ throw ApiError.BadRequest(
|
|
|
+ "peIdNotFound",
|
|
|
+ "ID сущности участия не передан",
|
|
|
+ );
|
|
|
+ const pe = await cPeService.getPeWithValues(peId);
|
|
|
+ const members = await cPeService.getMembers(peId);
|
|
|
+ if (!pe)
|
|
|
+ throw ApiError.BadRequest("peNotFound", "Сущность участия не найдена");
|
|
|
+
|
|
|
+ const fullPe = {
|
|
|
+ ...pe,
|
|
|
+ members: [...members],
|
|
|
+ };
|
|
|
+ const validationResult = validatePeForAct(actRegData, fullPe);
|
|
|
+ if (!validationResult.isValid)
|
|
|
+ throw ApiError.BadRequest(
|
|
|
+ "peValidatorFailed",
|
|
|
+ validationResult.messages.join(", "),
|
|
|
+ );
|
|
|
+ }
|
|
|
//
|
|
|
|
|
|
// валидация формы
|
|
@@ -422,12 +442,28 @@ class ClientActivitiesController {
|
|
|
// вставляем в базу и сохраняем файлы
|
|
|
const activityRegId = v7();
|
|
|
await updPool.transaction(async (tr) => {
|
|
|
- tr.query(sql.unsafe`
|
|
|
+ if (actRegData.isUserReg) {
|
|
|
+ // для user
|
|
|
+ tr.query(sql.unsafe`
|
|
|
+ insert into act.activity_regs
|
|
|
+ (activity_reg_id, activity_id, user_id)
|
|
|
+ values
|
|
|
+ (${activityRegId}, ${actRegData.activityId}, ${user.userId})
|
|
|
+ `);
|
|
|
+ } else {
|
|
|
+ // для pe
|
|
|
+ if (!peId)
|
|
|
+ throw ApiError.BadRequest(
|
|
|
+ "peIdNotFound",
|
|
|
+ "ID сущности участия не передан",
|
|
|
+ );
|
|
|
+ tr.query(sql.unsafe`
|
|
|
insert into act.activity_regs
|
|
|
(activity_reg_id, activity_id, pe_id)
|
|
|
values
|
|
|
(${activityRegId}, ${actRegData.activityId}, ${peId})
|
|
|
`);
|
|
|
+ }
|
|
|
|
|
|
await cCustomFieldsValidateService.saveCustomFieldValuesInTransaction({
|
|
|
tr,
|