Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LWangllix committed Feb 5, 2024
1 parent 7c63c6f commit 574e1a4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 43 deletions.
12 changes: 0 additions & 12 deletions mixins/database.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ export default function (opts: any = {}) {
return;
},

async update(ctx: any) {
return this.updateEntity(
ctx,
{
...ctx.params,
},
{
...ctx.options,
}
);
},

async removeAllEntities(ctx: any) {
return await this.clearEntities(ctx);
},
Expand Down
51 changes: 29 additions & 22 deletions services/forms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,21 @@ const populatePermissions = (field: string) => {

if (entity.assigneeId === value) return value;

const error = 'Assignee cannot be set.';

if (user.type === UserType.USER) {
throwBadRequestError(error);
}

const availableAssigneeList: { rows: User[] } = await ctx.call(
'forms.getAssignees'
);
const assigneeAuthUser = availableAssigneeList.rows.find(
(assignee) => assignee.id === Number(value)
);

if (user.type === UserType.USER || !assigneeAuthUser) {
throwBadRequestError('Assignee cannot be set.');
if (!assigneeAuthUser) {
throwBadRequestError(error);
}

const localUser: User = await ctx.call('users.findOrCreate', {
Expand Down Expand Up @@ -399,6 +405,8 @@ export default class FormsService extends moleculer.Service {
],
total: 1,
page: 1,
pageSize: 10,
totalPages: 1,
};

return await ctx.call('auth.users.list', {
Expand All @@ -410,7 +418,6 @@ export default class FormsService extends moleculer.Service {
},
},
fields: ['id', 'firstName', 'lastName', 'phone', 'email', 'type'],
pageSize: 99999,
});
}

Expand Down Expand Up @@ -544,7 +551,7 @@ export default class FormsService extends moleculer.Service {

let canAssign = true;

if (isCreatedByUser || authUser?.type === UserType.USER) {
if (isCreatedByUser || user?.type === UserType.USER) {
canAssign = false;
}

Expand Down Expand Up @@ -685,6 +692,24 @@ export default class FormsService extends moleculer.Service {
async 'forms.updated'(ctx: Context<EntityChangedParams<Form>>) {
const { oldData: prevForm, data: form } = ctx.params;

if (prevForm?.status !== form.status) {
const { comment } = ctx.options?.parentCtx?.params as any;
const typesByStatus = {
[FormStatus.SUBMITTED]: FormHistoryTypes.UPDATED,
[FormStatus.REJECTED]: FormHistoryTypes.REJECTED,
[FormStatus.RETURNED]: FormHistoryTypes.RETURNED,
[FormStatus.APPROVED]: FormHistoryTypes.APPROVED,
};

await ctx.call('forms.histories.create', {
form: form.id,
comment,
type: typesByStatus[form.status],
});

await this.sendNotificationOnStatusChange(form);
}

if (!!form?.assignee && prevForm?.assignee !== form?.assignee) {
const assignee: User = await ctx.call('users.resolve', {
id: form.assignee,
Expand All @@ -706,24 +731,6 @@ export default class FormsService extends moleculer.Service {
object.id
);
}

if (prevForm?.status !== form.status) {
const { comment } = ctx.options?.parentCtx?.params as any;
const typesByStatus = {
[FormStatus.SUBMITTED]: FormHistoryTypes.UPDATED,
[FormStatus.REJECTED]: FormHistoryTypes.REJECTED,
[FormStatus.RETURNED]: FormHistoryTypes.RETURNED,
[FormStatus.APPROVED]: FormHistoryTypes.APPROVED,
};

await ctx.call('forms.histories.create', {
form: form.id,
comment,
type: typesByStatus[form.status],
});

await this.sendNotificationOnStatusChange(form);
}
}

@Event()
Expand Down
11 changes: 3 additions & 8 deletions services/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,9 @@ export default class UsersService extends moleculer.Service {
};

if (user?.id) {
return ctx.call(
'users.update',
{
id: user.id,
...dataToSave,
},
{ scope } as any
);
return this.updateEntity(ctx, dataToSave, {
scope,
});
}

// let user to customize his phone and email
Expand Down
2 changes: 1 addition & 1 deletion utils/mails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function notifyFormAssignee(
To: email.toLowerCase(),
TemplateId: 34487978,
TemplateModel: {
actionUrl: `${hostUrl()}/uetk/teikimo-anketos/${formId}`,
actionUrl: `${hostUrl(true)}/uetk/teikimo-anketos/${formId}`,
typeText: formTypeTranslates[formType] || 'teikimo',
objectName,
},
Expand Down

0 comments on commit 574e1a4

Please sign in to comment.