diff --git a/package.json b/package.json index 6e33326..306d668 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@beincom/dto", - "version": "4.5.5", + "version": "4.5.6", "description": "Share dto for all projects of Beincom", "main": "./dist/index.js", "scripts": { diff --git a/src/activity-log/enums/activity-log-use-case.enum.ts b/src/activity-log/enums/activity-log-use-case.enum.ts index bf86241..7e56e99 100644 --- a/src/activity-log/enums/activity-log-use-case.enum.ts +++ b/src/activity-log/enums/activity-log-use-case.enum.ts @@ -65,4 +65,8 @@ export enum ACTIVITY_LOG_USE_CASES { CANCEL_INVITATION = 'cancel.invitation', ACCEPT_INVITATION = 'accept.invitation', DECLINE_INVITATION = 'decline.invitation', + + /** Community **/ + DELETE_COMMUNITY = 'delete.community', + RECOVER_COMMUNITY = 'recover.community', } diff --git a/src/activity-log/use-cases/community/delete-recover-community.use-case.ts b/src/activity-log/use-cases/community/delete-recover-community.use-case.ts new file mode 100644 index 0000000..f51ed2d --- /dev/null +++ b/src/activity-log/use-cases/community/delete-recover-community.use-case.ts @@ -0,0 +1,100 @@ +import { + ActivityLogBaseUseCase, + BasePayloadPropsDTO, + } from '../../activity-log-base-use-case.dto'; + import { + ActivityLogCommunityDTO, + ActivityLogDocumentDTO, + ActivityLogObjectDataDTO, + ActivityLogObjectIdDTO, + ActivityLogPayloadDTO, + ActivityLogUserDTO, + } from '../../dtos'; + import { ACTIVITY_EVENT_TYPES, ACTIVITY_LOG_USE_CASES, ACTIVITY_OBJECT_TYPES } from '../../enums'; + +export enum DeletedCommunityState { + RESTORED = 'recoverd', + TEMPORARY_DELETED = 'temporary-deleted', +} + + export type DeleteRecoverCommunityPayload = { + community: ActivityLogCommunityDTO; + state: DeletedCommunityState; + }; + + type PayloadDTO = BasePayloadPropsDTO & DeleteRecoverCommunityPayload; + + type DataDTO = {actor: ActivityLogUserDTO} & DeleteRecoverCommunityPayload; + + class DeleteRecoverCommunityLog extends ActivityLogBaseUseCase { + static readonly useCase: + | ACTIVITY_LOG_USE_CASES.DELETE_COMMUNITY + | ACTIVITY_LOG_USE_CASES.RECOVER_COMMUNITY + = ACTIVITY_LOG_USE_CASES.DELETE_COMMUNITY; + static readonly eventType: ACTIVITY_EVENT_TYPES.DELETE | ACTIVITY_EVENT_TYPES.UPDATE = ACTIVITY_EVENT_TYPES.DELETE; + static readonly objectType = ACTIVITY_OBJECT_TYPES.COMMUNITY; + + public static toPayload(data: PayloadDTO): ActivityLogPayloadDTO { + return { + useCase: this.useCase, + eventTime: Date.now(), + data, + }; + } + + public static toDocument({ + eventTime, + data, + }: ActivityLogPayloadDTO): ActivityLogDocumentDTO { + const { id, mainId, actor, community, state } = data; + + return { + id, + mainId, + eventTime, + useCase: this.useCase, + eventType: this.eventType, + objectType: this.objectType, + actorId: actor ? actor.id : undefined, + communityId: community.id, + objectId: community.id, + groupId: community.id, + data: { + actor, + community, + state + }, + }; + } + + public toObjectIds(): ActivityLogObjectIdDTO { + const { actorId } = this.document; + + return { + userIds: [actorId].filter((id) => id), + }; + } + + public toData(objectData: ActivityLogObjectDataDTO): DataDTO { + const { actorId, data } = this.document; + + return { + ...data, + actor: objectData.users[actorId], + }; + } + } + + export class DeleteCommunityLog extends DeleteRecoverCommunityLog { + static readonly useCase = ACTIVITY_LOG_USE_CASES.DELETE_COMMUNITY; + static readonly eventType = ACTIVITY_EVENT_TYPES.DELETE; + static readonly objectType = ACTIVITY_OBJECT_TYPES.COMMUNITY; + } + + export class RecoverCommunityLog extends DeleteRecoverCommunityLog { + static readonly useCase = ACTIVITY_LOG_USE_CASES.RECOVER_COMMUNITY; + static readonly eventType = ACTIVITY_EVENT_TYPES.UPDATE; + static readonly objectType = ACTIVITY_OBJECT_TYPES.COMMUNITY; + } + + \ No newline at end of file diff --git a/src/activity-log/use-cases/community/index.ts b/src/activity-log/use-cases/community/index.ts new file mode 100644 index 0000000..959e022 --- /dev/null +++ b/src/activity-log/use-cases/community/index.ts @@ -0,0 +1 @@ +export * from './delete-recover-community.use-case'; diff --git a/src/activity-log/use-cases/group/delete-recover-group.use-case.ts b/src/activity-log/use-cases/group/delete-recover-group.use-case.ts index e60830c..a0fb9cc 100644 --- a/src/activity-log/use-cases/group/delete-recover-group.use-case.ts +++ b/src/activity-log/use-cases/group/delete-recover-group.use-case.ts @@ -12,20 +12,20 @@ import { } from '../../dtos'; import { ACTIVITY_EVENT_TYPES, ACTIVITY_LOG_USE_CASES, ACTIVITY_OBJECT_TYPES } from '../../enums'; -export enum DeletedState { +export enum DeletedGroupState { DELETED = 'deleted', RESTORED = 'recoverd', TEMPORARY_DELETED = 'temporary-deleted', } -export type DeleteRecoverGroupState = { +export type DeleteRecoverGroupPayload = { group: ActivityLogGroupDTO; - state: DeletedState; + state: DeletedGroupState; }; -type PayloadDTO = BasePayloadPropsDTO & DeleteRecoverGroupState; +type PayloadDTO = BasePayloadPropsDTO & DeleteRecoverGroupPayload; -type DataDTO = {actor: ActivityLogUserDTO} & DeleteRecoverGroupState; +type DataDTO = {actor: ActivityLogUserDTO} & DeleteRecoverGroupPayload; class DeleteRecoverGroupLog extends ActivityLogBaseUseCase { static readonly useCase: diff --git a/src/activity-log/use-cases/index.ts b/src/activity-log/use-cases/index.ts index b46bf63..2966c0e 100644 --- a/src/activity-log/use-cases/index.ts +++ b/src/activity-log/use-cases/index.ts @@ -5,3 +5,4 @@ export * from './group-member'; export * from './group-set'; export * from './scheme'; export * from './invitation'; +export * from './community';