Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions src/activity-log/enums/activity-log-use-case.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Original file line number Diff line number Diff line change
@@ -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<DataDTO> {
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<PayloadDTO> {
return {
useCase: this.useCase,
eventTime: Date.now(),
data,
};
}

public static toDocument({
eventTime,
data,
}: ActivityLogPayloadDTO<PayloadDTO>): ActivityLogDocumentDTO<DataDTO> {
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;
}


1 change: 1 addition & 0 deletions src/activity-log/use-cases/community/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './delete-recover-community.use-case';
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataDTO> {
static readonly useCase:
Expand Down
1 change: 1 addition & 0 deletions src/activity-log/use-cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './group-member';
export * from './group-set';
export * from './scheme';
export * from './invitation';
export * from './community';