|
@@ -1,5 +1,10 @@
|
|
|
import { apiTypes } from "#api/current-api.js";
|
|
|
-import { CustomFieldWithValue } from "#api/v_0.1.0/types/custom-fields-types.js";
|
|
|
+import {
|
|
|
+ CustomFieldWithUserCopyValue,
|
|
|
+ CustomFieldWithValidators,
|
|
|
+ CustomFieldWithValidatorsAndValue,
|
|
|
+ CustomFieldWithValue,
|
|
|
+} from "#api/v_0.1.0/types/custom-fields-types.js";
|
|
|
import { DbSchema } from "#db/db-schema.js";
|
|
|
import { selPool, updPool } from "#db/db.js";
|
|
|
import { ApiError } from "#exceptions/api-error.js";
|
|
@@ -64,6 +69,7 @@ class CActService {
|
|
|
isPaymentOpen: DbSchema.act.actRegStatuses.isPaymentOpen,
|
|
|
}),
|
|
|
),
|
|
|
+ isUserReg: DbSchema.act.activities.isUserReg,
|
|
|
}),
|
|
|
)`
|
|
|
select
|
|
@@ -76,7 +82,8 @@ class CActService {
|
|
|
ar.pe_owner_id "peOwnerId",
|
|
|
ar.user_id "userId",
|
|
|
ar.is_paid "isPaid",
|
|
|
- ar.status_history "statusHistory"
|
|
|
+ ar.status_history "statusHistory",
|
|
|
+ ar.is_user_reg "isUserReg"
|
|
|
from
|
|
|
act.act_regs_with_status ar
|
|
|
where
|
|
@@ -125,6 +132,7 @@ class CActService {
|
|
|
DbSchema.act.activityRegFormFields.isChangeResetStatus,
|
|
|
}),
|
|
|
),
|
|
|
+ isUserReg: DbSchema.act.activities.isUserReg,
|
|
|
}),
|
|
|
)`
|
|
|
select
|
|
@@ -138,7 +146,8 @@ class CActService {
|
|
|
ar.user_id "userId",
|
|
|
ar.is_paid "isPaid",
|
|
|
ar.status_history "statusHistory",
|
|
|
- ar.fields "fields"
|
|
|
+ ar.fields "fields",
|
|
|
+ ar.is_user_reg "isUserReg"
|
|
|
from
|
|
|
act.act_regs_with_values ar
|
|
|
where
|
|
@@ -171,6 +180,7 @@ class CActService {
|
|
|
isPaymentOpen: DbSchema.act.actRegStatuses.isPaymentOpen,
|
|
|
}),
|
|
|
),
|
|
|
+ isUserReg: DbSchema.act.activities.isUserReg,
|
|
|
}),
|
|
|
)`
|
|
|
select
|
|
@@ -183,7 +193,8 @@ class CActService {
|
|
|
ar.pe_owner_id "peOwnerId",
|
|
|
ar.user_id "userId",
|
|
|
ar.is_paid "isPaid",
|
|
|
- ar.status_history "statusHistory"
|
|
|
+ ar.status_history "statusHistory",
|
|
|
+ ar.is_user_reg "isUserReg"
|
|
|
from
|
|
|
act.act_regs_with_values ar
|
|
|
where
|
|
@@ -267,17 +278,17 @@ class CActService {
|
|
|
|
|
|
// оплата за всю регистрацию
|
|
|
if (activity.paymentConfig === "PER_REGISTRATION") {
|
|
|
-const isPaid = await this.checkActivityRegPayment({
|
|
|
+ const isPaid = await this.checkActivityRegPayment({
|
|
|
activityRegId,
|
|
|
});
|
|
|
if (isPaid) {
|
|
|
- await updPool.query(sql.unsafe`
|
|
|
+ await updPool.query(sql.unsafe`
|
|
|
update act.activity_regs
|
|
|
set is_paid = true
|
|
|
where activity_reg_id = ${activityRegId}
|
|
|
`);
|
|
|
|
|
|
- await updPool.query(sql.unsafe`
|
|
|
+ await updPool.query(sql.unsafe`
|
|
|
insert into act.act_reg_status_history (
|
|
|
activity_reg_id,
|
|
|
act_reg_status_id,
|
|
@@ -289,7 +300,7 @@ const isPaid = await this.checkActivityRegPayment({
|
|
|
'Оплачено'
|
|
|
)
|
|
|
`);
|
|
|
-}
|
|
|
+ }
|
|
|
|
|
|
// TODO: QR
|
|
|
}
|
|
@@ -403,6 +414,237 @@ const isPaid = await this.checkActivityRegPayment({
|
|
|
|
|
|
return undefined;
|
|
|
}
|
|
|
+
|
|
|
+ async getActRegDataWithUserCopyValuesAndActValidators(
|
|
|
+ userId: string,
|
|
|
+ eventId: string,
|
|
|
+ activityCode: string,
|
|
|
+ ) {
|
|
|
+ return await selPool.maybeOne(sql.type(
|
|
|
+ z.object({
|
|
|
+ activityId: DbSchema.act.activities.activityId,
|
|
|
+ code: DbSchema.act.activities.code,
|
|
|
+ publicName: DbSchema.act.activities.publicName,
|
|
|
+ eventInstId: DbSchema.act.activities.eventInstId,
|
|
|
+ categoryId: DbSchema.act.activities.categoryId,
|
|
|
+ categoryCode: DbSchema.act.activityCategories.code,
|
|
|
+ validators: z.array(apiTypes.activities.ActValidator),
|
|
|
+ peTypes: z.array(
|
|
|
+ z.object({
|
|
|
+ peTypeId: DbSchema.act.peTypes.peTypeId,
|
|
|
+ code: DbSchema.act.peTypes.code,
|
|
|
+ name: DbSchema.act.peTypes.name,
|
|
|
+ }),
|
|
|
+ ),
|
|
|
+ fields: z.array(
|
|
|
+ CustomFieldWithUserCopyValue.extend({ arffId: z.string() }),
|
|
|
+ ),
|
|
|
+ isUserReg: DbSchema.act.activities.isUserReg,
|
|
|
+ }),
|
|
|
+ )`
|
|
|
+ select
|
|
|
+ a.activity_id "activityId",
|
|
|
+ a.code,
|
|
|
+ a.public_name "publicName",
|
|
|
+ a.event_inst_id "eventInstId",
|
|
|
+ a.category_id "categoryId",
|
|
|
+ a.category_code "categoryCode",
|
|
|
+ a.validators,
|
|
|
+ a.pe_types "peTypes",
|
|
|
+ coalesce(f.fields, '[]'::jsonb) "fields",
|
|
|
+ a.is_user_reg "isUserReg"
|
|
|
+ from
|
|
|
+ act.act_with_validators a
|
|
|
+ left join lateral (
|
|
|
+ select
|
|
|
+ jsonb_agg(jsonb_build_object(
|
|
|
+ 'fieldDefinitionId', f.field_definition_id,
|
|
|
+ 'arffId', af.arff_id,
|
|
|
+ 'isCopyUserValue', af.is_copy_user_value,
|
|
|
+ 'code', f.code,
|
|
|
+ 'userCopyValue', ufwv.value,
|
|
|
+ 'fieldTypeCode', f.field_type_code,
|
|
|
+ 'title', COALESCE(af.field_title_override, f.title),
|
|
|
+ 'mask', f.mask,
|
|
|
+ 'options', f."options",
|
|
|
+ 'validators', f.validators
|
|
|
+ )) as fields
|
|
|
+ from
|
|
|
+ act.activity_reg_form_fields af
|
|
|
+ left join cf.custom_fields_with_validators f on
|
|
|
+ f.field_definition_id = af.field_definition_id
|
|
|
+ -- значение из профиля юзера
|
|
|
+ left join ev.user_fields_with_values ufwv on
|
|
|
+ af.field_definition_id = ufwv.field_definition_id
|
|
|
+ and ufwv.user_id = ${userId}
|
|
|
+ and ufwv.event_id = ${eventId}
|
|
|
+ and ufwv.value is not null
|
|
|
+ -- только если нужно копировать
|
|
|
+ and af.is_copy_user_value = true
|
|
|
+ where
|
|
|
+ af.activity_id = a.activity_id
|
|
|
+ ) f on true
|
|
|
+ where a.code = ${activityCode}
|
|
|
+ `);
|
|
|
+ }
|
|
|
+
|
|
|
+ async getActRegDataWithFieldsAndValidatorsAndActValidators(
|
|
|
+ activityCode: string,
|
|
|
+ ) {
|
|
|
+ return await selPool.maybeOne(sql.type(
|
|
|
+ z.object({
|
|
|
+ activityId: DbSchema.act.activities.activityId,
|
|
|
+ code: DbSchema.act.activities.code,
|
|
|
+ publicName: DbSchema.act.activities.publicName,
|
|
|
+ eventInstId: DbSchema.act.activities.eventInstId,
|
|
|
+ categoryId: DbSchema.act.activities.categoryId,
|
|
|
+ categoryCode: DbSchema.act.activityCategories.code,
|
|
|
+ validators: z.array(apiTypes.activities.ActValidator),
|
|
|
+ peTypes: z.array(
|
|
|
+ z.object({
|
|
|
+ peTypeId: DbSchema.act.peTypes.peTypeId,
|
|
|
+ code: DbSchema.act.peTypes.code,
|
|
|
+ name: DbSchema.act.peTypes.name,
|
|
|
+ }),
|
|
|
+ ),
|
|
|
+ fields: z.array(
|
|
|
+ CustomFieldWithValidators.extend({ arffId: z.string() }),
|
|
|
+ ),
|
|
|
+ isUserReg: DbSchema.act.activities.isUserReg,
|
|
|
+ }),
|
|
|
+ )`
|
|
|
+ select
|
|
|
+ a.activity_id "activityId",
|
|
|
+ a.code,
|
|
|
+ a.public_name "publicName",
|
|
|
+ a.event_inst_id "eventInstId",
|
|
|
+ a.category_id "categoryId",
|
|
|
+ a.category_code "categoryCode",
|
|
|
+ a.validators,
|
|
|
+ a.pe_types "peTypes",
|
|
|
+ coalesce(f.fields, '[]'::jsonb) "fields",
|
|
|
+ a.is_user_reg "isUserReg"
|
|
|
+ from
|
|
|
+ act.act_with_validators a
|
|
|
+ left join lateral (
|
|
|
+ select
|
|
|
+ jsonb_agg(jsonb_build_object(
|
|
|
+ 'fieldDefinitionId', f.field_definition_id,
|
|
|
+ 'arffId', af.arff_id,
|
|
|
+ 'isCopyUserValue', af.is_copy_user_value,
|
|
|
+ 'code', f.code,
|
|
|
+ 'fieldTypeCode', f.field_type_code,
|
|
|
+ 'title', COALESCE(af.field_title_override, f.title),
|
|
|
+ 'mask', f.mask,
|
|
|
+ 'options', f."options",
|
|
|
+ 'validators', f.validators
|
|
|
+ )) as fields
|
|
|
+ from
|
|
|
+ act.activity_reg_form_fields af
|
|
|
+ left join cf.custom_fields_with_validators f on
|
|
|
+ f.field_definition_id = af.field_definition_id
|
|
|
+ where
|
|
|
+ af.activity_id = a.activity_id
|
|
|
+ ) f on true
|
|
|
+ where a.code = ${activityCode}
|
|
|
+ `);
|
|
|
+ }
|
|
|
+
|
|
|
+ async getActRegWithFieldsAndValidatorsAndValuesAndActValidators(
|
|
|
+ activityRegId: string,
|
|
|
+ ) {
|
|
|
+ return selPool.maybeOne(sql.type(
|
|
|
+ z.object({
|
|
|
+ activityRegId: DbSchema.act.activityRegs.activityRegId,
|
|
|
+ activityId: DbSchema.act.activityRegs.activityId,
|
|
|
+ activityCode: DbSchema.act.activities.code,
|
|
|
+ activityPublicName: DbSchema.act.activities.publicName,
|
|
|
+ peId: DbSchema.act.activityRegs.peId,
|
|
|
+ peName: DbSchema.act.partEntities.name.nullable(),
|
|
|
+ peOwnerId: DbSchema.act.partEntities.ownerId.nullable(),
|
|
|
+ userId: DbSchema.act.activityRegs.userId.nullable(),
|
|
|
+ isPaid: DbSchema.act.activityRegs.isPaid,
|
|
|
+ validators: z.array(apiTypes.activities.ActValidator),
|
|
|
+ statusHistory: z.array(
|
|
|
+ z.object({
|
|
|
+ statusHistoryId: DbSchema.act.actRegStatusHistory.statusHistoryId,
|
|
|
+ name: DbSchema.act.actRegStatuses.name,
|
|
|
+ code: DbSchema.act.actRegStatuses.code,
|
|
|
+ note: DbSchema.act.actRegStatusHistory.note,
|
|
|
+ setDate: DbSchema.act.actRegStatusHistory.setDate,
|
|
|
+ actRegStatusId: DbSchema.act.actRegStatuses.actRegStatusId,
|
|
|
+ color: DbSchema.act.actRegStatuses.color,
|
|
|
+ isPaymentOpen: DbSchema.act.actRegStatuses.isPaymentOpen,
|
|
|
+ }),
|
|
|
+ ),
|
|
|
+ fields: z.array(
|
|
|
+ CustomFieldWithValidatorsAndValue.extend({
|
|
|
+ arffId: DbSchema.act.activityRegFormFields.arffId,
|
|
|
+ isChangeResetStatus:
|
|
|
+ DbSchema.act.activityRegFormFields.isChangeResetStatus,
|
|
|
+ }),
|
|
|
+ ),
|
|
|
+ isUserReg: DbSchema.act.activities.isUserReg,
|
|
|
+ peTypes: z.array(
|
|
|
+ z.object({
|
|
|
+ peTypeId: DbSchema.act.peTypes.peTypeId,
|
|
|
+ code: DbSchema.act.peTypes.code,
|
|
|
+ name: DbSchema.act.peTypes.name,
|
|
|
+ }),
|
|
|
+ ),
|
|
|
+ }),
|
|
|
+ )`
|
|
|
+ select
|
|
|
+ ar.activity_reg_id "activityRegId",
|
|
|
+ ar.activity_id "activityId",
|
|
|
+ ar.activity_code "activityCode",
|
|
|
+ ar.activity_public_name "activityPublicName",
|
|
|
+ ar.pe_id "peId",
|
|
|
+ ar.pe_name "peName",
|
|
|
+ ar.pe_owner_id "peOwnerId",
|
|
|
+ ar.user_id "userId",
|
|
|
+ ar.is_paid "isPaid",
|
|
|
+ ar.status_history "statusHistory",
|
|
|
+ f.fields "fields",
|
|
|
+ awv.validators,
|
|
|
+ ar.is_user_reg "isUserReg",
|
|
|
+ awv.pe_types "peTypes"
|
|
|
+ from
|
|
|
+ act.act_regs_with_status ar
|
|
|
+ left join lateral (
|
|
|
+ select
|
|
|
+ jsonb_agg(jsonb_build_object(
|
|
|
+ 'fieldDefinitionId', cfd.field_definition_id,
|
|
|
+ 'arffId', f_1.arff_id,
|
|
|
+ 'isCopyUserValue', f_1.is_copy_user_value,
|
|
|
+ 'code', cfd.code,
|
|
|
+ 'value', afv.value,
|
|
|
+ 'fieldTypeCode', ft.code,
|
|
|
+ 'title', coalesce(f_1.field_title_override, cfd.title),
|
|
|
+ 'mask', cfd.mask,
|
|
|
+ 'options', cfd.options,
|
|
|
+ 'isChangeResetStatus', f_1.is_change_reset_status,
|
|
|
+ 'validators', cfwv.validators
|
|
|
+ )) as fields
|
|
|
+ from
|
|
|
+ act.activity_reg_form_fields f_1
|
|
|
+ left join cf.custom_field_definitions cfd on
|
|
|
+ f_1.field_definition_id = cfd.field_definition_id
|
|
|
+ left join cf.field_types ft on
|
|
|
+ cfd.field_type_id = ft.field_type_id
|
|
|
+ left join act.ar_field_values afv on
|
|
|
+ f_1.arff_id = afv.arff_id
|
|
|
+ and afv.activity_reg_id = ar.activity_reg_id
|
|
|
+ left join cf.custom_fields_with_validators cfwv on
|
|
|
+ cfwv.field_definition_id = cfd.field_definition_id
|
|
|
+ where
|
|
|
+ f_1.activity_id = ar.activity_id) f on
|
|
|
+ true
|
|
|
+ left join act.act_with_validators awv on
|
|
|
+ awv.activity_id = ar.activity_id
|
|
|
+ where ar.activity_reg_id = ${activityRegId}
|
|
|
+ `);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export const cActService = new CActService();
|