@hed-hog/core 0.0.325 → 0.0.327
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.module.d.ts.map +1 -1
- package/dist/core.module.js +3 -0
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/integration/services/outbox.processor.d.ts.map +1 -1
- package/dist/integration/services/outbox.processor.js +1 -0
- package/dist/integration/services/outbox.processor.js.map +1 -1
- package/dist/integration/types/event.types.d.ts +1 -0
- package/dist/integration/types/event.types.d.ts.map +1 -1
- package/dist/mail/mail.controller.d.ts +2 -0
- package/dist/mail/mail.controller.d.ts.map +1 -1
- package/dist/mail/mail.module.d.ts.map +1 -1
- package/dist/mail/mail.module.js +33 -53
- package/dist/mail/mail.module.js.map +1 -1
- package/dist/mail/mail.service.d.ts +5 -1
- package/dist/mail/mail.service.d.ts.map +1 -1
- package/dist/mail/mail.service.js +64 -84
- package/dist/mail/mail.service.js.map +1 -1
- package/dist/role/role.service.d.ts +3 -1
- package/dist/role/role.service.d.ts.map +1 -1
- package/dist/role/role.service.js +33 -5
- package/dist/role/role.service.js.map +1 -1
- package/dist/setting/setting.service.d.ts.map +1 -1
- package/dist/setting/setting.service.js +1 -0
- package/dist/setting/setting.service.js.map +1 -1
- package/dist/user/user.service.d.ts +3 -1
- package/dist/user/user.service.d.ts.map +1 -1
- package/dist/user/user.service.js +31 -4
- package/dist/user/user.service.js.map +1 -1
- package/dist/webhook-integration/event-webhook.controller.d.ts +29 -0
- package/dist/webhook-integration/event-webhook.controller.d.ts.map +1 -0
- package/dist/webhook-integration/event-webhook.controller.js +93 -0
- package/dist/webhook-integration/event-webhook.controller.js.map +1 -0
- package/dist/webhook-integration/event-webhook.service.d.ts +54 -0
- package/dist/webhook-integration/event-webhook.service.d.ts.map +1 -0
- package/dist/webhook-integration/event-webhook.service.js +334 -0
- package/dist/webhook-integration/event-webhook.service.js.map +1 -0
- package/dist/webhook-integration/integration-event-catalog.controller.d.ts +21 -0
- package/dist/webhook-integration/integration-event-catalog.controller.d.ts.map +1 -0
- package/dist/webhook-integration/integration-event-catalog.controller.js +91 -0
- package/dist/webhook-integration/integration-event-catalog.controller.js.map +1 -0
- package/dist/webhook-integration/integration-event-catalog.service.d.ts +26 -0
- package/dist/webhook-integration/integration-event-catalog.service.d.ts.map +1 -0
- package/dist/webhook-integration/integration-event-catalog.service.js +112 -0
- package/dist/webhook-integration/integration-event-catalog.service.js.map +1 -0
- package/dist/webhook-integration/webhook-integration.controller.d.ts +44 -0
- package/dist/webhook-integration/webhook-integration.controller.d.ts.map +1 -0
- package/dist/webhook-integration/webhook-integration.controller.js +181 -0
- package/dist/webhook-integration/webhook-integration.controller.js.map +1 -0
- package/dist/webhook-integration/webhook-integration.module.d.ts +3 -0
- package/dist/webhook-integration/webhook-integration.module.d.ts.map +1 -0
- package/dist/webhook-integration/webhook-integration.module.js +54 -0
- package/dist/webhook-integration/webhook-integration.module.js.map +1 -0
- package/dist/webhook-integration/webhook-integration.service.d.ts +73 -0
- package/dist/webhook-integration/webhook-integration.service.d.ts.map +1 -0
- package/dist/webhook-integration/webhook-integration.service.js +569 -0
- package/dist/webhook-integration/webhook-integration.service.js.map +1 -0
- package/dist/webhook-integration/webhook-utils.d.ts +7 -0
- package/dist/webhook-integration/webhook-utils.d.ts.map +1 -0
- package/dist/webhook-integration/webhook-utils.js +104 -0
- package/dist/webhook-integration/webhook-utils.js.map +1 -0
- package/hedhog/data/integration_event_catalog.yaml +118 -0
- package/hedhog/data/mail_profile.yaml +18 -0
- package/hedhog/data/menu.yaml +26 -12
- package/hedhog/data/route.yaml +152 -8
- package/hedhog/data/setting_group.yaml +7 -156
- package/hedhog/data/setting_subgroup.yaml +0 -32
- package/hedhog/frontend/app/configurations/[slug]/components/setting-field.tsx.ejs +205 -0
- package/hedhog/frontend/app/integrations-webhooks/page.tsx.ejs +1835 -0
- package/hedhog/frontend/messages/en.json +2 -1
- package/hedhog/frontend/messages/pt.json +2 -1
- package/hedhog/table/event_webhook.yaml +55 -0
- package/hedhog/table/event_webhook_delivery_log.yaml +66 -0
- package/hedhog/table/event_webhook_event.yaml +26 -0
- package/hedhog/table/integration_event_catalog.yaml +41 -0
- package/hedhog/table/setting.yaml +1 -0
- package/hedhog/table/webhook_action.yaml +85 -0
- package/hedhog/table/webhook_call_log.yaml +46 -0
- package/hedhog/table/webhook_integration.yaml +43 -0
- package/package.json +3 -3
- package/src/core.module.ts +10 -7
- package/src/index.ts +10 -5
- package/src/integration/services/outbox.processor.ts +5 -4
- package/src/integration/types/event.types.ts +4 -3
- package/src/mail/mail.module.ts +36 -59
- package/src/mail/mail.service.ts +84 -89
- package/src/role/role.service.ts +41 -8
- package/src/setting/setting.service.ts +7 -6
- package/src/user/user.service.ts +34 -3
- package/src/webhook-integration/event-webhook.controller.ts +50 -0
- package/src/webhook-integration/event-webhook.service.ts +384 -0
- package/src/webhook-integration/integration-event-catalog.controller.ts +50 -0
- package/src/webhook-integration/integration-event-catalog.service.ts +117 -0
- package/src/webhook-integration/webhook-integration.controller.ts +103 -0
- package/src/webhook-integration/webhook-integration.module.ts +45 -0
- package/src/webhook-integration/webhook-integration.service.ts +735 -0
- package/src/webhook-integration/webhook-utils.ts +79 -0
package/src/mail/mail.service.ts
CHANGED
|
@@ -59,7 +59,7 @@ export class MailService implements OnModuleInit {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
private isMailConfigSlug(slug: string) {
|
|
62
|
-
return slug
|
|
62
|
+
return slug === 'mail-profile-id';
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
private isSettingEnabled(value: unknown) {
|
|
@@ -68,26 +68,21 @@ export class MailService implements OnModuleInit {
|
|
|
68
68
|
|
|
69
69
|
private async syncConfiguredMailFlag() {
|
|
70
70
|
try {
|
|
71
|
-
const settings = await this.setting.getSettingValues([
|
|
72
|
-
|
|
73
|
-
'mail-from',
|
|
74
|
-
]);
|
|
71
|
+
const settings = await this.setting.getSettingValues(['mail-profile-id']);
|
|
72
|
+
const profileId = settings['mail-profile-id'];
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
const from = String(settings['mail-from'] || '').trim();
|
|
78
|
-
|
|
79
|
-
if (!provider || !from) {
|
|
74
|
+
if (!profileId || Number(profileId) <= 0) {
|
|
80
75
|
await this.setting.setValue('configured-mail', 'false');
|
|
81
76
|
return;
|
|
82
77
|
}
|
|
83
78
|
|
|
84
|
-
await this.reloadConfig();
|
|
79
|
+
const { from, config } = await this.reloadConfig();
|
|
85
80
|
|
|
86
81
|
await this.mailMainService.send({
|
|
87
82
|
to: from,
|
|
88
83
|
from,
|
|
89
84
|
subject: '[HedHog] Mail configuration validation',
|
|
90
|
-
body: `This is an automatic validation email for the configured
|
|
85
|
+
body: `This is an automatic validation email for the configured profile (id: ${profileId}).`,
|
|
91
86
|
});
|
|
92
87
|
|
|
93
88
|
await this.setting.setValue('configured-mail', 'true');
|
|
@@ -100,86 +95,91 @@ export class MailService implements OnModuleInit {
|
|
|
100
95
|
}
|
|
101
96
|
|
|
102
97
|
/**
|
|
103
|
-
* Reload mail configuration from database and update MailMainService
|
|
98
|
+
* Reload mail configuration from database and update MailMainService.
|
|
99
|
+
* Returns the active from address and the built config object.
|
|
104
100
|
*/
|
|
105
|
-
async reloadConfig() {
|
|
101
|
+
async reloadConfig(): Promise<{ success: boolean; provider: string; from: string; config: any }> {
|
|
106
102
|
try {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
slug: {
|
|
110
|
-
in: [
|
|
111
|
-
'mail-provider',
|
|
112
|
-
'mail-from',
|
|
113
|
-
'mail-gmail-client-id',
|
|
114
|
-
'mail-gmail-client-secret',
|
|
115
|
-
'mail-gmail-refresh-token',
|
|
116
|
-
'mail-smtp-host',
|
|
117
|
-
'mail-smtp-port',
|
|
118
|
-
'mail-smtp-secure',
|
|
119
|
-
'mail-client-secret',
|
|
120
|
-
'mail-aws-access-key-id',
|
|
121
|
-
'mail-aws-secret-access-key',
|
|
122
|
-
'mail-aws-region'
|
|
123
|
-
]
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
select: {
|
|
127
|
-
slug: true,
|
|
128
|
-
value: true,
|
|
129
|
-
}
|
|
130
|
-
});
|
|
103
|
+
const settings = await this.setting.getSettingValues(['mail-profile-id']);
|
|
104
|
+
const profileId = Number(settings['mail-profile-id']);
|
|
131
105
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
settings.set(setting.slug, setting.value);
|
|
106
|
+
if (!profileId || profileId <= 0) {
|
|
107
|
+
throw new BadRequestException('No mail profile configured. Set a mail profile in the Mail settings.');
|
|
135
108
|
}
|
|
136
109
|
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
Object.assign(config, {
|
|
144
|
-
type: 'GMAIL',
|
|
145
|
-
clientId: settings.get('mail-gmail-client-id'),
|
|
146
|
-
clientSecret: settings.get('mail-gmail-client-secret'),
|
|
147
|
-
refreshToken: settings.get('mail-gmail-refresh-token'),
|
|
148
|
-
from: settings.get('mail-from'),
|
|
149
|
-
});
|
|
150
|
-
break;
|
|
151
|
-
case 'SMTP':
|
|
152
|
-
Object.assign(config, {
|
|
153
|
-
type: 'SMTP',
|
|
154
|
-
host: settings.get('mail-smtp-host'),
|
|
155
|
-
port: Number(settings.get('mail-smtp-port')),
|
|
156
|
-
secure: settings.get('mail-smtp-secure') === 'true',
|
|
157
|
-
username: settings.get('mail-from'),
|
|
158
|
-
password: settings.get('mail-client-secret'),
|
|
159
|
-
});
|
|
160
|
-
break;
|
|
161
|
-
case 'SES':
|
|
162
|
-
Object.assign(config, {
|
|
163
|
-
type: 'SES',
|
|
164
|
-
region: settings.get('mail-aws-region'),
|
|
165
|
-
accessKeyId: settings.get('mail-aws-access-key-id'),
|
|
166
|
-
secretAccessKey: settings.get('mail-aws-secret-access-key'),
|
|
167
|
-
from: settings.get('mail-from'),
|
|
168
|
-
});
|
|
169
|
-
break;
|
|
170
|
-
default:
|
|
171
|
-
throw new BadRequestException(`Invalid mail provider: ${settings.get('mail-provider')}`);
|
|
110
|
+
const profile = await this.prismaService.mail_profile.findUnique({
|
|
111
|
+
where: { id: profileId },
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (!profile) {
|
|
115
|
+
throw new NotFoundException(`Mail profile with id ${profileId} not found.`);
|
|
172
116
|
}
|
|
173
117
|
|
|
118
|
+
const config = this.buildMailConfig(profile);
|
|
119
|
+
|
|
174
120
|
this.mailMainService.setConfig(config);
|
|
175
|
-
this.logger.log(
|
|
176
|
-
|
|
121
|
+
this.logger.log(`Mail configuration reloaded from profile "${profile.name}" (${profile.provider})`);
|
|
122
|
+
|
|
123
|
+
const from = profile.from_name
|
|
124
|
+
? `${profile.from_name} <${profile.from_email}>`
|
|
125
|
+
: profile.from_email;
|
|
126
|
+
|
|
127
|
+
return { success: true, provider: profile.provider, from, config };
|
|
177
128
|
} catch (error) {
|
|
178
129
|
this.logger.error('Error reloading mail configuration:', error);
|
|
179
130
|
throw error;
|
|
180
131
|
}
|
|
181
132
|
}
|
|
182
133
|
|
|
134
|
+
private buildMailConfig(profile: {
|
|
135
|
+
provider: string;
|
|
136
|
+
from_email: string;
|
|
137
|
+
smtp_host?: string | null;
|
|
138
|
+
smtp_port?: number | null;
|
|
139
|
+
smtp_secure?: boolean | null;
|
|
140
|
+
smtp_username?: string | null;
|
|
141
|
+
smtp_password?: string | null;
|
|
142
|
+
gmail_client_id?: string | null;
|
|
143
|
+
gmail_client_secret?: string | null;
|
|
144
|
+
gmail_refresh_token?: string | null;
|
|
145
|
+
ses_access_key_id?: string | null;
|
|
146
|
+
ses_secret_access_key?: string | null;
|
|
147
|
+
ses_region?: string | null;
|
|
148
|
+
}): any {
|
|
149
|
+
switch (profile.provider) {
|
|
150
|
+
case 'GMAIL':
|
|
151
|
+
return {
|
|
152
|
+
global: true,
|
|
153
|
+
type: 'GMAIL' as const,
|
|
154
|
+
clientId: profile.gmail_client_id ?? '',
|
|
155
|
+
clientSecret: profile.gmail_client_secret ?? '',
|
|
156
|
+
refreshToken: profile.gmail_refresh_token ?? '',
|
|
157
|
+
from: profile.from_email,
|
|
158
|
+
};
|
|
159
|
+
case 'SMTP':
|
|
160
|
+
return {
|
|
161
|
+
global: true,
|
|
162
|
+
type: 'SMTP' as const,
|
|
163
|
+
host: profile.smtp_host ?? '',
|
|
164
|
+
port: profile.smtp_port ?? 587,
|
|
165
|
+
secure: profile.smtp_secure ?? false,
|
|
166
|
+
username: profile.smtp_username ?? '',
|
|
167
|
+
password: profile.smtp_password ?? '',
|
|
168
|
+
};
|
|
169
|
+
case 'SES':
|
|
170
|
+
return {
|
|
171
|
+
global: true,
|
|
172
|
+
type: 'SES' as const,
|
|
173
|
+
region: profile.ses_region ?? '',
|
|
174
|
+
accessKeyId: profile.ses_access_key_id ?? '',
|
|
175
|
+
secretAccessKey: profile.ses_secret_access_key ?? '',
|
|
176
|
+
from: profile.from_email,
|
|
177
|
+
};
|
|
178
|
+
default:
|
|
179
|
+
throw new BadRequestException(`Invalid mail provider: ${profile.provider}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
183
|
async list(locale: string, paginationParams: PaginationDTO) {
|
|
184
184
|
const result = await this.localeService.listModelWithLocale(
|
|
185
185
|
locale,
|
|
@@ -391,11 +391,7 @@ export class MailService implements OnModuleInit {
|
|
|
391
391
|
locale: string,
|
|
392
392
|
{ email, slug, variables }: SendTemplatedMailDTO,
|
|
393
393
|
) {
|
|
394
|
-
|
|
395
|
-
const settings = await this.setting.getSettingValues([
|
|
396
|
-
'configured-mail',
|
|
397
|
-
'mail-from'
|
|
398
|
-
]);
|
|
394
|
+
const settings = await this.setting.getSettingValues(['configured-mail']);
|
|
399
395
|
|
|
400
396
|
if (!this.isSettingEnabled(settings['configured-mail'])) {
|
|
401
397
|
this.logger.warn('Mail service is not configured. Aborting sending email.');
|
|
@@ -403,7 +399,7 @@ export class MailService implements OnModuleInit {
|
|
|
403
399
|
}
|
|
404
400
|
|
|
405
401
|
try {
|
|
406
|
-
|
|
402
|
+
const { from } = await this.reloadConfig();
|
|
407
403
|
const localeRecord = await this.getLocaleRecord(locale);
|
|
408
404
|
const mail = await this.getMailTemplate(slug, localeRecord.id);
|
|
409
405
|
const { subject, body } = mail.mail_locale[0];
|
|
@@ -412,7 +408,7 @@ export class MailService implements OnModuleInit {
|
|
|
412
408
|
|
|
413
409
|
await this.mailMainService.send({
|
|
414
410
|
to: email,
|
|
415
|
-
from
|
|
411
|
+
from,
|
|
416
412
|
subject: parsedSubject,
|
|
417
413
|
body: parsedBody,
|
|
418
414
|
mail_id: mail.id,
|
|
@@ -481,15 +477,14 @@ export class MailService implements OnModuleInit {
|
|
|
481
477
|
}: TestMailDTO) {
|
|
482
478
|
const localeRecord = await this.getLocaleRecord(locale);
|
|
483
479
|
const mail = await this.getMailTemplate(slug, localeRecord.id);
|
|
484
|
-
const settings = await this.setting.getSettingValues([
|
|
485
|
-
'configured-mail',
|
|
486
|
-
'mail-from'
|
|
487
|
-
]);
|
|
480
|
+
const settings = await this.setting.getSettingValues(['configured-mail']);
|
|
488
481
|
|
|
489
482
|
if (!this.isSettingEnabled(settings['configured-mail'])) {
|
|
490
483
|
throw new BadRequestException('Mail service is not configured.');
|
|
491
484
|
}
|
|
492
485
|
|
|
486
|
+
const { from } = await this.reloadConfig();
|
|
487
|
+
|
|
493
488
|
try {
|
|
494
489
|
const parsedSubject = variables
|
|
495
490
|
? this.interpolateTemplate(subject, variables)
|
|
@@ -503,7 +498,7 @@ export class MailService implements OnModuleInit {
|
|
|
503
498
|
subject: parsedSubject,
|
|
504
499
|
body: parsedBody,
|
|
505
500
|
mail_id: mail.id,
|
|
506
|
-
from
|
|
501
|
+
from,
|
|
507
502
|
});
|
|
508
503
|
} catch (error) {
|
|
509
504
|
this.logger.error('Error sending test mail:', error);
|
package/src/role/role.service.ts
CHANGED
|
@@ -2,14 +2,15 @@ import { LocaleService, getLocaleText } from '@hed-hog/api-locale';
|
|
|
2
2
|
import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
|
|
3
3
|
import { PrismaService } from '@hed-hog/api-prisma';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
BadRequestException,
|
|
6
|
+
Inject,
|
|
7
|
+
Injectable,
|
|
8
|
+
NotFoundException,
|
|
9
|
+
forwardRef,
|
|
10
10
|
} from '@nestjs/common';
|
|
11
11
|
import { DeleteDTO } from '../dto/delete.dto';
|
|
12
12
|
import { UpdateIdsDTO } from '../dto/update-ids.dto';
|
|
13
|
+
import { IntegrationDeveloperApiService } from '../integration/services/integration-developer-api.service';
|
|
13
14
|
import { CreateDTO } from './dto/create.dto';
|
|
14
15
|
import { UpdateDTO } from './dto/update.dto';
|
|
15
16
|
|
|
@@ -22,6 +23,8 @@ export class RoleService {
|
|
|
22
23
|
private readonly paginationService: PaginationService,
|
|
23
24
|
@Inject(forwardRef(() => LocaleService))
|
|
24
25
|
private readonly localeService: LocaleService,
|
|
26
|
+
@Inject(forwardRef(() => IntegrationDeveloperApiService))
|
|
27
|
+
private readonly integrationApi: IntegrationDeveloperApiService,
|
|
25
28
|
) {}
|
|
26
29
|
|
|
27
30
|
async updateUsers(roleId: number, { ids }: UpdateIdsDTO):Promise<{count:number}> {
|
|
@@ -421,7 +424,17 @@ export class RoleService {
|
|
|
421
424
|
);
|
|
422
425
|
}
|
|
423
426
|
|
|
424
|
-
|
|
427
|
+
const result = await this.get(role.id);
|
|
428
|
+
|
|
429
|
+
await this.integrationApi.publishEvent({
|
|
430
|
+
eventName: 'core.role.created',
|
|
431
|
+
sourceModule: 'core',
|
|
432
|
+
aggregateType: 'role',
|
|
433
|
+
aggregateId: String(role.id),
|
|
434
|
+
payload: { id: role.id, slug },
|
|
435
|
+
}).catch(() => null);
|
|
436
|
+
|
|
437
|
+
return result;
|
|
425
438
|
}
|
|
426
439
|
|
|
427
440
|
async update(id: number, body: UpdateDTO, localeRequest:string) {
|
|
@@ -470,7 +483,17 @@ export class RoleService {
|
|
|
470
483
|
);
|
|
471
484
|
}
|
|
472
485
|
|
|
473
|
-
|
|
486
|
+
const result = await this.get(id);
|
|
487
|
+
|
|
488
|
+
await this.integrationApi.publishEvent({
|
|
489
|
+
eventName: 'core.role.updated',
|
|
490
|
+
sourceModule: 'core',
|
|
491
|
+
aggregateType: 'role',
|
|
492
|
+
aggregateId: String(id),
|
|
493
|
+
payload: { id, slug: body.slug },
|
|
494
|
+
}).catch(() => null);
|
|
495
|
+
|
|
496
|
+
return result;
|
|
474
497
|
}
|
|
475
498
|
|
|
476
499
|
async delete({ ids }: DeleteDTO, localeRequest: string = 'en'):Promise<{count:number}> {
|
|
@@ -494,12 +517,22 @@ export class RoleService {
|
|
|
494
517
|
throw new NotFoundException(getLocaleText('itemsNotFound', localeRequest, `Roles with IDs ${missingIds.join(', ')} not found`).replace('{{items}}', 'Roles'));
|
|
495
518
|
}
|
|
496
519
|
|
|
497
|
-
|
|
520
|
+
const result = await this.prismaService.role.deleteMany({
|
|
498
521
|
where: {
|
|
499
522
|
id: {
|
|
500
523
|
in: ids,
|
|
501
524
|
},
|
|
502
525
|
},
|
|
503
526
|
});
|
|
527
|
+
|
|
528
|
+
await this.integrationApi.publishEvent({
|
|
529
|
+
eventName: 'core.role.deleted',
|
|
530
|
+
sourceModule: 'core',
|
|
531
|
+
aggregateType: 'role',
|
|
532
|
+
aggregateId: ids.join(','),
|
|
533
|
+
payload: { ids },
|
|
534
|
+
}).catch(() => null);
|
|
535
|
+
|
|
536
|
+
return result;
|
|
504
537
|
}
|
|
505
538
|
}
|
|
@@ -3,12 +3,12 @@ import { getLocaleText, LocaleService } from '@hed-hog/api-locale';
|
|
|
3
3
|
import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
|
|
4
4
|
import { PrismaService, setting_type_0f055cd5ea_enum } from '@hed-hog/api-prisma';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
BadRequestException,
|
|
7
|
+
forwardRef,
|
|
8
|
+
Inject,
|
|
9
|
+
Injectable,
|
|
10
|
+
Logger,
|
|
11
|
+
NotFoundException
|
|
12
12
|
} from '@nestjs/common';
|
|
13
13
|
import * as pako from 'pako';
|
|
14
14
|
import { IntegrationDeveloperApiService } from '../integration/services/integration-developer-api.service';
|
|
@@ -214,6 +214,7 @@ export class SettingService {
|
|
|
214
214
|
'providers',
|
|
215
215
|
'disable-authentication-with-email-and-password',
|
|
216
216
|
'contact-allow-company-registration',
|
|
217
|
+
'operations.comment-edit-window',
|
|
217
218
|
];
|
|
218
219
|
const setting = await this.getSettingValues(slugs);
|
|
219
220
|
return { locales, setting };
|
package/src/user/user.service.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { ChallengeService } from '../challenge/challenge.service';
|
|
12
12
|
import { DeleteDTO } from '../dto/delete.dto';
|
|
13
13
|
import { FileService } from '../file/file.service';
|
|
14
|
+
import { IntegrationDeveloperApiService } from '../integration/services/integration-developer-api.service';
|
|
14
15
|
import { SecurityService } from '../security/security.service';
|
|
15
16
|
import { USER_AVATAR_UPLOAD_DESTINATION } from './constants/user.constants';
|
|
16
17
|
import { CreateWithEmailAndPasswordDTO } from './dto/create-with-email-and-password.dto';
|
|
@@ -64,7 +65,9 @@ export class UserService {
|
|
|
64
65
|
@Inject(forwardRef(() => ChallengeService))
|
|
65
66
|
private readonly challenge: ChallengeService,
|
|
66
67
|
@Inject(forwardRef(() => FileService))
|
|
67
|
-
private readonly file: FileService
|
|
68
|
+
private readonly file: FileService,
|
|
69
|
+
@Inject(forwardRef(() => IntegrationDeveloperApiService))
|
|
70
|
+
private readonly integrationApi: IntegrationDeveloperApiService,
|
|
68
71
|
) { }
|
|
69
72
|
|
|
70
73
|
// ==========================================
|
|
@@ -195,16 +198,34 @@ export class UserService {
|
|
|
195
198
|
const challenge = await this.challenge.verifyEmail(locale, user.id, email);
|
|
196
199
|
await this.registerUserActivity(user.id, 'register');
|
|
197
200
|
|
|
201
|
+
await this.integrationApi.publishEvent({
|
|
202
|
+
eventName: 'core.user.created',
|
|
203
|
+
sourceModule: 'core',
|
|
204
|
+
aggregateType: 'user',
|
|
205
|
+
aggregateId: String(user.id),
|
|
206
|
+
payload: { id: user.id, name: user.name, email },
|
|
207
|
+
}).catch(() => null);
|
|
208
|
+
|
|
198
209
|
return { user, challenge };
|
|
199
210
|
}
|
|
200
211
|
|
|
201
212
|
async update(locale: string, userId: number, { name }: UpdateDTO) {
|
|
202
213
|
const user = await this.findUserById(locale, userId);
|
|
203
214
|
|
|
204
|
-
|
|
215
|
+
const result = await this.prismaService.user.update({
|
|
205
216
|
where: { id: user.id },
|
|
206
217
|
data: { name: name ?? user.name },
|
|
207
218
|
});
|
|
219
|
+
|
|
220
|
+
await this.integrationApi.publishEvent({
|
|
221
|
+
eventName: 'core.user.updated',
|
|
222
|
+
sourceModule: 'core',
|
|
223
|
+
aggregateType: 'user',
|
|
224
|
+
aggregateId: String(userId),
|
|
225
|
+
payload: { id: userId, name: result.name },
|
|
226
|
+
}).catch(() => null);
|
|
227
|
+
|
|
228
|
+
return result;
|
|
208
229
|
}
|
|
209
230
|
|
|
210
231
|
async resetPassword(
|
|
@@ -261,9 +282,19 @@ export class UserService {
|
|
|
261
282
|
);
|
|
262
283
|
}
|
|
263
284
|
|
|
264
|
-
|
|
285
|
+
const result = await this.prismaService.user.deleteMany({
|
|
265
286
|
where: { id: { in: ids } },
|
|
266
287
|
});
|
|
288
|
+
|
|
289
|
+
await this.integrationApi.publishEvent({
|
|
290
|
+
eventName: 'core.user.deleted',
|
|
291
|
+
sourceModule: 'core',
|
|
292
|
+
aggregateType: 'user',
|
|
293
|
+
aggregateId: ids.join(','),
|
|
294
|
+
payload: { ids },
|
|
295
|
+
}).catch(() => null);
|
|
296
|
+
|
|
297
|
+
return result;
|
|
267
298
|
}
|
|
268
299
|
|
|
269
300
|
// ==========================================
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DeleteDTO, Role } from '@hed-hog/api';
|
|
2
|
+
import { Pagination } from '@hed-hog/api-pagination';
|
|
3
|
+
import {
|
|
4
|
+
Body,
|
|
5
|
+
Controller,
|
|
6
|
+
Delete,
|
|
7
|
+
Get,
|
|
8
|
+
Param,
|
|
9
|
+
ParseIntPipe,
|
|
10
|
+
Patch,
|
|
11
|
+
Post,
|
|
12
|
+
} from '@nestjs/common';
|
|
13
|
+
import { EventWebhookService } from './event-webhook.service';
|
|
14
|
+
|
|
15
|
+
@Role()
|
|
16
|
+
@Controller('event-webhook')
|
|
17
|
+
export class EventWebhookController {
|
|
18
|
+
constructor(private readonly service: EventWebhookService) {}
|
|
19
|
+
|
|
20
|
+
@Get()
|
|
21
|
+
list(@Pagination() paginationParams) {
|
|
22
|
+
return this.service.list(paginationParams);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Get(':id')
|
|
26
|
+
get(@Param('id', ParseIntPipe) id: number) {
|
|
27
|
+
return this.service.get(id);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Post()
|
|
31
|
+
create(@Body() data: any) {
|
|
32
|
+
return this.service.create(data);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Patch(':id')
|
|
36
|
+
update(@Param('id', ParseIntPipe) id: number, @Body() data: any) {
|
|
37
|
+
return this.service.update(id, data);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Delete()
|
|
41
|
+
delete(@Body() data: DeleteDTO) {
|
|
42
|
+
return this.service.delete(data);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Get(':id/log')
|
|
46
|
+
logs(@Param('id', ParseIntPipe) id: number, @Pagination() paginationParams) {
|
|
47
|
+
return this.service.listLogs(id, paginationParams);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|