@comasoft/nestjs 0.1.43 → 0.1.45
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/category/category.service.d.ts +6 -3
- package/dist/category/category.service.js +1 -1
- package/dist/database/entities/notification.entity.js +1 -1
- package/dist/notifications/services/email.service.js +1 -1
- package/dist/notifications/services/kakao.service.d.ts +15 -3
- package/dist/notifications/services/kakao.service.js +1 -1
- package/dist/notifications/services/notification-send.service.js +1 -1
- package/dist/notifications/services/slack.service.d.ts +6 -1
- package/dist/notifications/services/slack.service.js +1 -1
- package/dist/services/file.service.d.ts +4 -4
- package/dist/services/file.service.js +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Repository } from 'typeorm';
|
|
1
|
+
import { DataSource, Repository } from 'typeorm';
|
|
2
2
|
import { Category } from '../database/entities';
|
|
3
3
|
import { CreateCategoryBaseDto, ResponseCategoriesBaseDto, ResponseCategoryBaseDto, UpdateCategoryBaseDto, UpdateCategorySortBaseDto } from './dto';
|
|
4
4
|
export declare class CategoryService {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
protected readonly repository: Repository<Category>;
|
|
6
|
+
protected readonly dataSource: DataSource;
|
|
7
|
+
constructor(repository: Repository<Category>, dataSource: DataSource);
|
|
8
|
+
protected validateCategoryLimit(type: string): Promise<void>;
|
|
9
|
+
protected checkCategoryUsage(id: number): Promise<void>;
|
|
7
10
|
create(body: CreateCategoryBaseDto): Promise<ResponseCategoryBaseDto<string>>;
|
|
8
11
|
findAll(type: string): Promise<ResponseCategoriesBaseDto<string>>;
|
|
9
12
|
findOne(id: number): Promise<ResponseCategoryBaseDto<string>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,t,o
|
|
1
|
+
var e=this&&this.__decorate||function(e,t,i,o){var r,n=arguments.length,s=n<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,o);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(s=(n<3?r(s):n>3?r(t,i,s):r(t,i))||s);return n>3&&s&&Object.defineProperty(t,i,s),s},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},i=this&&this.__param||function(e,t){return function(i,o){t(i,o,e)}},o=this&&this.__awaiter||function(e,t,i,o){return new(i||(i=Promise))(function(r,n){function fulfilled(e){try{step(o.next(e))}catch(e){n(e)}}function rejected(e){try{step(o.throw(e))}catch(e){n(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof i?e:new i(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((o=o.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CategoryService=void 0;const r=require("@nestjs/common"),n=require("@nestjs/typeorm"),s=require("class-transformer"),a=require("typeorm"),d=require("../database/entities"),c=require("../shared/error-codes"),p=require("./dto");let u=class CategoryService{constructor(e,t){this.repository=e,this.dataSource=t}validateCategoryLimit(e){return o(this,void 0,void 0,function*(){throw new r.BadRequestException("validateCategoryLimit must be implemented in app service")})}checkCategoryUsage(e){return o(this,void 0,void 0,function*(){throw new r.BadRequestException("checkCategoryUsage must be implemented in app service")})}create(e){return o(this,void 0,void 0,function*(){const{type:t,name:i,description:o,slug:n}=e;yield this.validateCategoryLimit(t);if(yield this.repository.findOne({where:{type:t,name:i}}))throw new r.ConflictException({message:"Category name already exists",error_code:c.ErrorCode.CATEGORY_NAME_ALREADY_EXISTS});const a=(yield this.repository.count({where:{type:t}}))+1,d=yield this.repository.save(Object.assign(Object.assign({},e),{sort:a}));return(0,s.plainToClass)(p.ResponseCategoryBaseDto,d)})}findAll(e){return o(this,void 0,void 0,function*(){const t=yield this.repository.find({where:{type:e},order:{sort:"ASC"}});return(0,s.plainToClass)(p.ResponseCategoriesBaseDto,{items:t})})}findOne(e){return o(this,void 0,void 0,function*(){const t=yield this.repository.findOne({where:{id:e}});if(!t)throw new r.NotFoundException(`Category with ID ${e} not found`);return(0,s.plainToClass)(p.ResponseCategoryBaseDto,t)})}update(e,t){return o(this,void 0,void 0,function*(){const i=yield this.repository.findOne({where:{id:e}});if(!i)throw new r.NotFoundException(`Category with ID ${e} not found`);if(yield this.repository.findOne({where:{type:i.type,name:t.name,id:(0,a.Not)(e)}}))throw new r.ConflictException({message:"Category name already exists",error_code:c.ErrorCode.CATEGORY_NAME_ALREADY_EXISTS});yield this.repository.update(e,t);const o=yield this.repository.findOne({where:{id:e}});return(0,s.plainToClass)(p.ResponseCategoryBaseDto,o)})}remove(e){return o(this,void 0,void 0,function*(){if(!(yield this.repository.findOne({where:{id:e}})))throw new r.NotFoundException(`Category with ID ${e} not found`);yield this.checkCategoryUsage(e),yield this.repository.update(e,{is_active:!1,deleted_at:new Date})})}updateSort(e){return o(this,void 0,void 0,function*(){const{items:t,type:i}=e,o=yield this.repository.find({where:{type:i}});if(o.length!==t.length)throw new r.BadRequestException("Invalid items ids provided");const n=o.map(e=>{var i;return Object.assign(Object.assign({},e),{sort:(null===(i=t.find(t=>t.id===e.id))||void 0===i?void 0:i.sort)||e.sort})});yield this.repository.save(n)})}};exports.CategoryService=u,exports.CategoryService=u=e([(0,r.Injectable)(),i(0,(0,n.InjectRepository)(d.Category)),t("design:paramtypes",[a.Repository,a.DataSource])],u);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=this&&this.__decorate||function(t,e,o,i){var n,r=arguments.length,a=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,o,i);else for(var p=t.length-1;p>=0;p--)(n=t[p])&&(a=(r<3?n(a):r>3?n(e,o,a):n(e,o))||a);return r>3&&a&&Object.defineProperty(e,o,a),a},e=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Notification=void 0;const o=require("typeorm"),i=require("../../enums.common"),n=require("./notification-recipient.entity");class Relations{}t([(0,o.OneToMany)(()=>n.NotificationRecipient,t=>t.notification),e("design:type",Array)],Relations.prototype,"recipients",void 0);let r=class Notification extends Relations{};exports.Notification=r,t([(0,o.PrimaryGeneratedColumn)(),e("design:type",Number)],r.prototype,"id",void 0),t([(0,o.Column)("varchar",{length:25}),e("design:type",String)],r.prototype,"type",void 0),t([(0,o.Column)("varchar",{length:
|
|
1
|
+
var t=this&&this.__decorate||function(t,e,o,i){var n,r=arguments.length,a=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,o,i);else for(var p=t.length-1;p>=0;p--)(n=t[p])&&(a=(r<3?n(a):r>3?n(e,o,a):n(e,o))||a);return r>3&&a&&Object.defineProperty(e,o,a),a},e=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Notification=void 0;const o=require("typeorm"),i=require("../../enums.common"),n=require("./notification-recipient.entity");class Relations{}t([(0,o.OneToMany)(()=>n.NotificationRecipient,t=>t.notification),e("design:type",Array)],Relations.prototype,"recipients",void 0);let r=class Notification extends Relations{};exports.Notification=r,t([(0,o.PrimaryGeneratedColumn)(),e("design:type",Number)],r.prototype,"id",void 0),t([(0,o.Column)("varchar",{length:25}),e("design:type",String)],r.prototype,"type",void 0),t([(0,o.Column)("varchar",{length:50}),e("design:type",String)],r.prototype,"template_key",void 0),t([(0,o.Column)("enum",{enum:i.NOTIFICATION_STATUS}),e("design:type",String)],r.prototype,"status",void 0),t([(0,o.Column)("varchar",{length:50,nullable:!0}),e("design:type",String)],r.prototype,"sender",void 0),t([(0,o.Column)("varchar",{length:100,nullable:!0}),e("design:type",String)],r.prototype,"title",void 0),t([(0,o.Column)("text",{nullable:!0}),e("design:type",String)],r.prototype,"content",void 0),t([(0,o.CreateDateColumn)({type:"timestamptz"}),e("design:type",Date)],r.prototype,"created_at",void 0),t([(0,o.UpdateDateColumn)({type:"timestamptz"}),e("design:type",Date)],r.prototype,"updated_at",void 0),t([(0,o.DeleteDateColumn)({type:"timestamptz"}),e("design:type",Date)],r.prototype,"deleted_at",void 0),exports.Notification=r=t([(0,o.Entity)("notifications"),(0,o.Index)(["id"],{where:"deleted_at IS NULL"}),(0,o.Index)(["status"])],r);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,t,i,n){var s,
|
|
1
|
+
var e=this&&this.__decorate||function(e,t,i,n){var s,o=arguments.length,c=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,i,n);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(c=(o<3?s(c):o>3?s(t,i,c):s(t,i))||c);return o>3&&c&&Object.defineProperty(t,i,c),c},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},i=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))(function(s,o){function fulfilled(e){try{step(n.next(e))}catch(e){o(e)}}function rejected(e){try{step(n.throw(e))}catch(e){o(e)}}function step(e){e.done?s(e.value):function adopt(e){return e instanceof i?e:new i(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.EmailService=void 0;const n=require("@aws-sdk/client-ses"),s=require("@nestjs/common"),o=require("@nestjs/config");let c=class EmailService{constructor(e){this.configService=e,"aws"===this.configService.get("EMAIL_PROVIDER")&&(this.sesClient=new n.SESClient({region:this.configService.get("AWS_REGION"),credentials:{accessKeyId:this.configService.get("AWS_ACCESS_KEY_ID"),secretAccessKey:this.configService.get("AWS_SECRET_ACCESS_KEY")}}))}send(e){return i(this,void 0,void 0,function*(){const t=this.configService.get("EMAIL_PROVIDER");if(!t||!this.configService.get("EMAIL_FROM"))throw new Error("EMAIL_PROVIDER or EMAIL_FROM is not set");return"aws"===t?this.sendAws(e):[]})}sendAws(e){return i(this,void 0,void 0,function*(){if("production"===process.env.NODE_ENV){console.log("sendAws",e);for(const t of e){const e=new n.SendEmailCommand({Source:this.configService.get("EMAIL_NOREPLY_SOURCE"),Destination:{ToAddresses:[t.recipient]},Message:{Subject:{Data:t.subject,Charset:"UTF-8"},Body:{Html:{Data:t.text,Charset:"UTF-8"}}}}),i=yield this.sesClient.send(e);console.log(i)}}else console.log("sendAws",e)})}};exports.EmailService=c,exports.EmailService=c=e([(0,s.Injectable)(),t("design:paramtypes",[o.ConfigService])],c);
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { RedisService } from '../../redis';
|
|
2
3
|
export declare class KakaoService {
|
|
3
4
|
private readonly configService;
|
|
4
|
-
|
|
5
|
+
private readonly redis;
|
|
6
|
+
constructor(configService: ConfigService, redis: RedisService);
|
|
5
7
|
send(recipients: Array<{
|
|
6
8
|
recipient: string;
|
|
7
9
|
user_id: number;
|
|
10
|
+
sender_key: string;
|
|
8
11
|
template_code: string;
|
|
9
|
-
|
|
12
|
+
message: string;
|
|
10
13
|
}>): Promise<{
|
|
11
14
|
user_id: number;
|
|
12
15
|
recipient: string;
|
|
@@ -26,11 +29,20 @@ export declare class KakaoService {
|
|
|
26
29
|
messageId: string;
|
|
27
30
|
status: string;
|
|
28
31
|
}[]>;
|
|
32
|
+
private getPpurioToken;
|
|
33
|
+
sendPpurioMessage(recipient: {
|
|
34
|
+
recipient: string;
|
|
35
|
+
user_id: number;
|
|
36
|
+
sender_key: string;
|
|
37
|
+
template_code: string;
|
|
38
|
+
message: string;
|
|
39
|
+
}): Promise<any>;
|
|
29
40
|
sendPpurio(recipients: Array<{
|
|
30
41
|
recipient: string;
|
|
31
42
|
user_id: number;
|
|
43
|
+
sender_key: string;
|
|
32
44
|
template_code: string;
|
|
33
|
-
|
|
45
|
+
message: string;
|
|
34
46
|
}>): Promise<{
|
|
35
47
|
user_id: number;
|
|
36
48
|
recipient: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,t,i,
|
|
1
|
+
var e=this&&this.__decorate||function(e,t,i,o){var r,n=arguments.length,s=n<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,o);else for(var c=e.length-1;c>=0;c--)(r=e[c])&&(s=(n<3?r(s):n>3?r(t,i,s):r(t,i))||s);return n>3&&s&&Object.defineProperty(t,i,s),s},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},i=this&&this.__awaiter||function(e,t,i,o){return new(i||(i=Promise))(function(r,n){function fulfilled(e){try{step(o.next(e))}catch(e){n(e)}}function rejected(e){try{step(o.throw(e))}catch(e){n(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof i?e:new i(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((o=o.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.KakaoService=void 0;const o=require("@nestjs/common"),r=require("@nestjs/config"),n=require("../../redis");let s=class KakaoService{constructor(e,t){this.configService=e,this.redis=t}send(e){return i(this,void 0,void 0,function*(){const t=this.configService.get("KAKAO_PROVIDER");if(!t||!this.configService.get("KAKAO_FROM"))throw new Error("KAKAO_PROVIDER or KAKAO_FROM is not set");return"aligo"===t?this.sendAligo(e):"ppurio"===t?this.sendPpurio(e):[]})}sendAligo(e){return i(this,void 0,void 0,function*(){return console.log("📱 [KAKAO] Aligo 배열 발송:",{count:e.length,from:this.configService.get("KAKAO_FROM"),provider:"aligo",recipients:e.map(e=>({user_id:e.user_id,recipient:e.recipient,template_code:e.template_code,variables:e.variables})),timestamp:(new Date).toISOString()}),e.map(e=>({user_id:e.user_id,recipient:e.recipient,success:!0,messageId:`aligo-${Date.now()}-${e.user_id}`,status:"sent"}))})}getPpurioToken(){return i(this,void 0,void 0,function*(){if(yield this.redis.get("ppurio_token"))return yield this.redis.get("ppurio_token");const e=this.configService.get("PPURIO_ACCOUNT"),t=this.configService.get("PPURIO_PASSWORD"),i=btoa(`${e}:${t}`),o=yield fetch("https://api.bizppurio.com/v1/token",{method:"POST",headers:{"Content-Type":"application/json; charset=utf-8",Authorization:`Basic ${i}`},body:JSON.stringify({grant_type:"client_credentials"})}),r=yield o.json();if(r.accesstoken)return yield this.redis.set("ppurio_token",r.accesstoken,86e3),yield this.redis.get("ppurio_token");throw new Error(`cannot get ppurio access token: ${JSON.stringify(r)}`)})}sendPpurioMessage(e){return i(this,void 0,void 0,function*(){const t=yield this.getPpurioToken(),i=yield fetch("https://api.bizppurio.com/v3/message",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({account:this.configService.get("PPURIO_ACCOUNT"),refkey:this.configService.get("PPURIO_PASSWORD"),type:"at",from:this.configService.get("SMS_FROM"),to:e.recipient,content:{at:{senderkey:e.sender_key,templatecode:e.template_code,message:e.message}}})});return yield i.json()})}sendPpurio(e){return i(this,void 0,void 0,function*(){if("production"!==process.env.NODE_ENV)return void console.log("📱 [KAKAO] Ppurio 발송:",{count:e.length,from:this.configService.get("KAKAO_FROM"),provider:"ppurio",recipients:e.map(e=>({user_id:e.user_id,recipient:e.recipient,sender_key:e.sender_key,template_code:e.template_code,message:e.message})),timestamp:(new Date).toISOString()});const t=yield Promise.all(e.map(e=>this.sendPpurioMessage(e)));return console.log(t),e.map(e=>({user_id:e.user_id,recipient:e.recipient,success:!0,messageId:`ppurio-${Date.now()}-${e.user_id}`,status:"sent"}))})}};exports.KakaoService=s,exports.KakaoService=s=e([(0,o.Injectable)(),t("design:paramtypes",[r.ConfigService,n.RedisService])],s);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,t,i,s){var r,a=arguments.length,n=a<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,i,s);else for(var c=e.length-1;c>=0;c--)(r=e[c])&&(n=(a<3?r(n):a>3?r(t,i,n):r(t,i))||n);return a>3&&n&&Object.defineProperty(t,i,n),n},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},i=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))(function(r,a){function fulfilled(e){try{step(s.next(e))}catch(e){a(e)}}function rejected(e){try{step(s.throw(e))}catch(e){a(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof i?e:new i(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.NotificationSendService=void 0;const s=require("@nestjs/common"),r=require("./email.service"),a=require("./kakao.service"),n=require("./message-template.service"),c=require("./slack.service"),o=require("./sms.service");let l=class NotificationSendService{constructor(e,t,i,s,r){this.emailService=e,this.smsService=t,this.kakaoService=i,this.slackService=s,this.messageTemplateService=r}send(e){return i(this,void 0,void 0,function*(){switch(e.type){case"email":return this.sendEmail(e);case"sms":return this.sendSms(e);case"kakao":return this.sendKakao(e);case"slack":return this.sendSlack(e)}})}sendEmail(e){return i(this,void 0,void 0,function*(){const t=[];for(const i of e.recipients){let s,r;if(e.template_key){const t=yield this.messageTemplateService.getTemplate("email",e.template_key);if(!t)throw new Error("Template not found");const a=Object.assign(Object.assign({},e.variables),i.variables);s=this.messageTemplateService.renderTemplate(t,a),r=t.subject}else{if(!e.subject||!e.body)throw new Error("subject, body is required");s=e.body,r=e.subject}t.push({recipient:i.recipient,user_id:i.user_id,subject:r,text:s,variables:i.variables})}return yield this.emailService.send(t)})}sendSms(e){return i(this,void 0,void 0,function*(){const t=[];for(const i of e.recipients){let s;if(e.template_key){const t=yield this.messageTemplateService.getTemplate("sms",e.template_key);if(!t)throw new Error("Template not found");const r=Object.assign(Object.assign({},e.variables),i.variables);s=this.messageTemplateService.renderTemplate(t,r)}else{if(!e.message)throw new Error("message is required");s=e.message}t.push({recipient:i.recipient,user_id:i.user_id,message:s,variables:i.variables})}return yield this.smsService.send(t)})}sendKakao(e){return i(this,void 0,void 0,function*(){const t=e.recipients.
|
|
1
|
+
var e=this&&this.__decorate||function(e,t,i,s){var r,a=arguments.length,n=a<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,i,s);else for(var c=e.length-1;c>=0;c--)(r=e[c])&&(n=(a<3?r(n):a>3?r(t,i,n):r(t,i))||n);return a>3&&n&&Object.defineProperty(t,i,n),n},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},i=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))(function(r,a){function fulfilled(e){try{step(s.next(e))}catch(e){a(e)}}function rejected(e){try{step(s.throw(e))}catch(e){a(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof i?e:new i(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.NotificationSendService=void 0;const s=require("@nestjs/common"),r=require("./email.service"),a=require("./kakao.service"),n=require("./message-template.service"),c=require("./slack.service"),o=require("./sms.service");let l=class NotificationSendService{constructor(e,t,i,s,r){this.emailService=e,this.smsService=t,this.kakaoService=i,this.slackService=s,this.messageTemplateService=r}send(e){return i(this,void 0,void 0,function*(){switch(e.type){case"email":return this.sendEmail(e);case"sms":return this.sendSms(e);case"kakao":return this.sendKakao(e);case"slack":return this.sendSlack(e)}})}sendEmail(e){return i(this,void 0,void 0,function*(){const t=[];for(const i of e.recipients){let s,r;if(e.template_key){const t=yield this.messageTemplateService.getTemplate("email",e.template_key);if(!t)throw new Error("Template not found");const a=Object.assign(Object.assign({},e.variables),i.variables);s=this.messageTemplateService.renderTemplate(t,a),r=t.subject}else{if(!e.subject||!e.body)throw new Error("subject, body is required");s=e.body,r=e.subject}t.push({recipient:i.recipient,user_id:i.user_id,subject:r,text:s,variables:i.variables})}return yield this.emailService.send(t)})}sendSms(e){return i(this,void 0,void 0,function*(){const t=[];for(const i of e.recipients){let s;if(e.template_key){const t=yield this.messageTemplateService.getTemplate("sms",e.template_key);if(!t)throw new Error("Template not found");const r=Object.assign(Object.assign({},e.variables),i.variables);s=this.messageTemplateService.renderTemplate(t,r)}else{if(!e.message)throw new Error("message is required");s=e.message}t.push({recipient:i.recipient,user_id:i.user_id,message:s,variables:i.variables})}return yield this.smsService.send(t)})}sendKakao(e){return i(this,void 0,void 0,function*(){const t=[];for(const i of e.recipients){let s;if(!e.template_key)throw new Error("template_key is required");const r=yield this.messageTemplateService.getTemplate("kakao",e.template_key);if(!r)throw new Error("Template not found");const a=Object.assign(Object.assign({},e.variables),i.variables);s=this.messageTemplateService.renderTemplate(r,a),t.push({recipient:i.recipient,user_id:i.user_id,sender_key:r.sender_key,template_code:e.template_key,message:s})}return yield this.kakaoService.send(t)})}sendSlack(e){return i(this,void 0,void 0,function*(){let t;if(e.template_key){const i=yield this.messageTemplateService.getTemplate("slack",e.template_key);if(!i)throw new Error("Template not found");t=this.messageTemplateService.renderTemplate(i,e.variables||{})}else{if(!e.message)throw new Error("message is required");t=e.message}return[yield this.slackService.send(e.channel,t)]})}};exports.NotificationSendService=l,exports.NotificationSendService=l=e([(0,s.Injectable)(),t("design:paramtypes",[r.EmailService,o.SmsService,a.KakaoService,c.SlackService,n.MessageTemplateService])],l);
|
|
@@ -5,7 +5,12 @@ export declare class SlackService {
|
|
|
5
5
|
send(channel: string, message: string): Promise<{
|
|
6
6
|
channel: string;
|
|
7
7
|
success: boolean;
|
|
8
|
-
|
|
8
|
+
message: string;
|
|
9
9
|
status: string;
|
|
10
|
+
} | {
|
|
11
|
+
channel: string;
|
|
12
|
+
success: boolean;
|
|
13
|
+
status: string;
|
|
14
|
+
message?: undefined;
|
|
10
15
|
}>;
|
|
11
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,t,n,c){var o,r=arguments.length,i=r<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,n):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,c);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(r<3?o(i):r>3?o(t,n,i):o(t,n))||i);return r>3&&i&&Object.defineProperty(t,n,i),i},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},n=this&&this.__awaiter||function(e,t,n,c){return new(n||(n=Promise))(function(o,r){function fulfilled(e){try{step(c.next(e))}catch(e){r(e)}}function rejected(e){try{step(c.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof n?e:new n(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((c=c.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SlackService=void 0;const c=require("@nestjs/common"),o=require("@nestjs/config");let r=class SlackService{constructor(e){this.configService=e}send(e,t){return n(this,void 0,void 0,function*(){if(!this.configService.get("
|
|
1
|
+
var e=this&&this.__decorate||function(e,t,n,c){var o,r=arguments.length,i=r<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,n):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,c);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(r<3?o(i):r>3?o(t,n,i):o(t,n))||i);return r>3&&i&&Object.defineProperty(t,n,i),i},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},n=this&&this.__awaiter||function(e,t,n,c){return new(n||(n=Promise))(function(o,r){function fulfilled(e){try{step(c.next(e))}catch(e){r(e)}}function rejected(e){try{step(c.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof n?e:new n(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((c=c.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SlackService=void 0;const c=require("@nestjs/common"),o=require("@nestjs/config");let r=class SlackService{constructor(e){this.configService=e}send(e,t){return n(this,void 0,void 0,function*(){if(!this.configService.get("SLACK_WEBHOOK_URL"))throw new Error("SLACK_CHANNEL or SLACK_WEBHOOK_URL is not set");const n=yield fetch(this.configService.get("SLACK_WEBHOOK_URL"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t})});return n.ok?{channel:e,success:!0,status:"sent"}:{channel:e,success:!1,message:n.statusText,status:"sent"}})}};exports.SlackService=r,exports.SlackService=r=e([(0,c.Injectable)(),t("design:paramtypes",[o.ConfigService])],r);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DataSource, EntityManager } from 'typeorm';
|
|
2
2
|
import { S3Service } from '../aws/aws-s3.service';
|
|
3
|
-
import { FILE_STATUS } from '../enums.common';
|
|
4
3
|
import { File } from '../database/entities';
|
|
4
|
+
import { FILE_STATUS } from '../enums.common';
|
|
5
5
|
interface FileInput {
|
|
6
6
|
original_name: string;
|
|
7
7
|
file_name: string;
|
|
@@ -35,7 +35,7 @@ export declare class FileService {
|
|
|
35
35
|
target_id: number;
|
|
36
36
|
group_number?: number;
|
|
37
37
|
}): Promise<File[]>;
|
|
38
|
-
createPending({ target, user_id, files, manager, group_number
|
|
38
|
+
createPending({ target, user_id, files, manager, group_number }: CreateFileInput): Promise<({
|
|
39
39
|
sort: number;
|
|
40
40
|
group_number: number;
|
|
41
41
|
original_name: string;
|
|
@@ -49,7 +49,7 @@ export declare class FileService {
|
|
|
49
49
|
target_id: number;
|
|
50
50
|
user_id: number;
|
|
51
51
|
} & File)[]>;
|
|
52
|
-
statusCompleted({ target, target_id, user_id, file_ids, manager
|
|
53
|
-
softDelete({ target, target_id, user_id, delete_file_ids, manager
|
|
52
|
+
statusCompleted({ target, target_id, user_id, file_ids, manager }: StatusCompletedInput): Promise<void>;
|
|
53
|
+
softDelete({ target, target_id, user_id, delete_file_ids, manager }: SoftDeleteInput): Promise<void>;
|
|
54
54
|
}
|
|
55
55
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,t,r,i){var n,s=arguments.length,a=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,i);else for(var o=e.length-1;o>=0;o--)(n=e[o])&&(a=(s<3?n(a):s>3?n(t,r,a):n(t,r))||a);return s>3&&a&&Object.defineProperty(t,r,a),a},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},r=this&&this.__param||function(e,t){return function(r,i){t(r,i,e)}},i=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))(function(n,s){function fulfilled(e){try{step(i.next(e))}catch(e){s(e)}}function rejected(e){try{step(i.throw(e))}catch(e){s(e)}}function step(e){e.done?n(e.value):function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FileService=void 0;const n=require("@nestjs/common"),s=require("typeorm"),a=require("../aws/aws-s3.service"),o=require("../
|
|
1
|
+
var e=this&&this.__decorate||function(e,t,r,i){var n,s=arguments.length,a=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,i);else for(var o=e.length-1;o>=0;o--)(n=e[o])&&(a=(s<3?n(a):s>3?n(t,r,a):n(t,r))||a);return s>3&&a&&Object.defineProperty(t,r,a),a},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},r=this&&this.__param||function(e,t){return function(r,i){t(r,i,e)}},i=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))(function(n,s){function fulfilled(e){try{step(i.next(e))}catch(e){s(e)}}function rejected(e){try{step(i.throw(e))}catch(e){s(e)}}function step(e){e.done?n(e.value):function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FileService=void 0;const n=require("@nestjs/common"),s=require("typeorm"),a=require("../aws/aws-s3.service"),o=require("../database/entities"),c=require("../enums.common");let u=class FileService{constructor(e,t){this.dataSource=e,this.s3Service=t}findAll(e){return i(this,arguments,void 0,function*({target:e,target_id:t,group_number:r}){return this.dataSource.getRepository(o.File).find({where:{target:e,target_id:t,group_number:r}})})}createPending(e){return i(this,arguments,void 0,function*({target:e,user_id:t,files:r,manager:i,group_number:n}){const s=i?i.getRepository(o.File):this.dataSource.getRepository(o.File),a=yield s.save(r.map((r,i)=>{var s;return Object.assign(Object.assign({status:c.FILE_STATUS.PENDING,target:e,target_id:0,user_id:t},r),{sort:null!==(s=r.sort)&&void 0!==s?s:i+1,group_number:n})}));return a})}statusCompleted(e){return i(this,arguments,void 0,function*({target:e,target_id:t,user_id:r,file_ids:i,manager:n}){const a=n?n.getRepository(o.File):this.dataSource.getRepository(o.File);yield a.update({target:e,id:(0,s.In)(i)},{status:c.FILE_STATUS.COMPLETED,target_id:t})})}softDelete(e){return i(this,arguments,void 0,function*({target:e,target_id:t,user_id:r,delete_file_ids:i,manager:n}){const a=n?n.getRepository(o.File):this.dataSource.getRepository(o.File),u=yield a.find({where:{target:e,user_id:r,target_id:t,id:(0,s.In)(i)}});yield this.s3Service.deleteObjectsByKeys(u.map(e=>this.s3Service.getFileKey(e))),yield a.update({id:(0,s.In)(u.map(e=>e.id))},{status:c.FILE_STATUS.DELETED,deleted_at:new Date,is_active:!1})})}};exports.FileService=u,exports.FileService=u=e([(0,n.Injectable)(),r(1,(0,n.Inject)((0,n.forwardRef)(()=>a.S3Service))),t("design:paramtypes",[s.DataSource,a.S3Service])],u);
|