From 14008e69de218468ee6724a84e419e5a55af77a4 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Thu, 5 Dec 2019 10:55:19 +0300 Subject: [PATCH] feat(core): add application dtos #2222 --- .../packages/core/src/lib/models/dtos.ts | 124 ++++++++++++++++++ .../packages/core/src/lib/models/index.ts | 1 + 2 files changed, 125 insertions(+) create mode 100644 npm/ng-packs/packages/core/src/lib/models/dtos.ts diff --git a/npm/ng-packs/packages/core/src/lib/models/dtos.ts b/npm/ng-packs/packages/core/src/lib/models/dtos.ts new file mode 100644 index 0000000000..21bf136aa5 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/models/dtos.ts @@ -0,0 +1,124 @@ +export class ListResultDto { + items?: T[]; + + constructor(initialValues: Partial> = {}) { + for (const key in initialValues) { + if (initialValues.hasOwnProperty(key)) { + this[key] = initialValues[key]; + } + } + } +} + +export class PagedResultDto extends ListResultDto { + totalCount?: number; + + constructor(initialValues: Partial> = {}) { + super(initialValues); + } +} + +export class LimitedResultRequestDto { + maxResultCount = 10; + + constructor(initialValues: Partial = {}) { + for (const key in initialValues) { + if (initialValues.hasOwnProperty(key)) { + this[key] = initialValues[key]; + } + } + } +} + +export class PagedResultRequestDto extends LimitedResultRequestDto { + skipCount?: number; + + constructor(initialValues: Partial = {}) { + super(initialValues); + } +} + +export class PagedAndSortedResultRequestDto extends PagedResultRequestDto { + sorting?: string; + + constructor(initialValues: Partial = {}) { + super(initialValues); + } +} + +export class EntityDto { + id?: TKey; + + constructor(initialValues: Partial> = {}) { + for (const key in initialValues) { + if (initialValues.hasOwnProperty(key)) { + this[key] = initialValues[key]; + } + } + } +} + +export class CreationAuditedEntityDto extends EntityDto { + creationTime?: string | Date; + creatorId?: string; + + constructor(initialValues: Partial> = {}) { + super(initialValues); + } +} + +export class CreationAuditedEntityWithUserDto< + TUserDto, + TPrimaryKey = string +> extends CreationAuditedEntityDto { + creator?: TUserDto; + + constructor( + initialValues: Partial> = {}, + ) { + super(initialValues); + } +} + +export class AuditedEntityDto extends CreationAuditedEntityDto { + lastModificationTime?: string | Date; + lastModifierId?: string; + + constructor(initialValues: Partial> = {}) { + super(initialValues); + } +} + +export class AuditedEntityWithUserDto extends AuditedEntityDto< + TPrimaryKey +> { + creator?: TUserDto; + lastModifier?: TUserDto; + + constructor(initialValues: Partial> = {}) { + super(initialValues); + } +} + +export class FullAuditedEntityDto extends AuditedEntityDto { + isDeleted?: boolean; + deleterId?: string; + deletionTime?: Date | string; + + constructor(initialValues: Partial> = {}) { + super(initialValues); + } +} + +export class FullAuditedEntityWithUserDto< + TUserDto, + TPrimaryKey = string +> extends FullAuditedEntityDto { + creator?: TUserDto; + lastModifier?: TUserDto; + deleter?: TUserDto; + + constructor(initialValues: Partial> = {}) { + super(initialValues); + } +} diff --git a/npm/ng-packs/packages/core/src/lib/models/index.ts b/npm/ng-packs/packages/core/src/lib/models/index.ts index 63302c9ab8..e27f9359e3 100644 --- a/npm/ng-packs/packages/core/src/lib/models/index.ts +++ b/npm/ng-packs/packages/core/src/lib/models/index.ts @@ -1,6 +1,7 @@ export * from './application-configuration'; export * from './common'; export * from './config'; +export * from './dtos'; export * from './rest'; export * from './session'; export * from './profile';