@dirayaah/corporate-module 1.0.17
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/.prettierrc +4 -0
- package/README.md +93 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/jest.config.d.ts +0 -0
- package/dist/jest.config.js +10 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/src/constants/corporates-options.d.ts +1 -0
- package/dist/src/constants/corporates-options.js +5 -0
- package/dist/src/constants/corporates-options.js.map +1 -0
- package/dist/src/constants/index.d.ts +1 -0
- package/dist/src/constants/index.js +6 -0
- package/dist/src/constants/index.js.map +1 -0
- package/dist/src/dto/base.dto.d.ts +7 -0
- package/dist/src/dto/base.dto.js +7 -0
- package/dist/src/dto/base.dto.js.map +1 -0
- package/dist/src/dto/corporate.dto.d.ts +8 -0
- package/dist/src/dto/corporate.dto.js +46 -0
- package/dist/src/dto/corporate.dto.js.map +1 -0
- package/dist/src/dto/index.d.ts +2 -0
- package/dist/src/dto/index.js +6 -0
- package/dist/src/dto/index.js.map +1 -0
- package/dist/src/dto/rel-corporate-user.dto.d.ts +0 -0
- package/dist/src/dto/rel-corporate-user.dto.js +1 -0
- package/dist/src/dto/rel-corporate-user.dto.js.map +1 -0
- package/dist/src/entities/base.entity.d.ts +7 -0
- package/dist/src/entities/base.entity.js +37 -0
- package/dist/src/entities/base.entity.js.map +1 -0
- package/dist/src/entities/corporate.entity.d.ts +10 -0
- package/dist/src/entities/corporate.entity.js +46 -0
- package/dist/src/entities/corporate.entity.js.map +1 -0
- package/dist/src/entities/index.d.ts +3 -0
- package/dist/src/entities/index.js +8 -0
- package/dist/src/entities/index.js.map +1 -0
- package/dist/src/entities/pagination.d.ts +19 -0
- package/dist/src/entities/pagination.js +58 -0
- package/dist/src/entities/pagination.js.map +1 -0
- package/dist/src/entities/rel-corporate-user.entity.d.ts +6 -0
- package/dist/src/entities/rel-corporate-user.entity.js +30 -0
- package/dist/src/entities/rel-corporate-user.entity.js.map +1 -0
- package/dist/src/enum/corporate-status.enum.d.ts +4 -0
- package/dist/src/enum/corporate-status.enum.js +9 -0
- package/dist/src/enum/corporate-status.enum.js.map +1 -0
- package/dist/src/enum/index.d.ts +1 -0
- package/dist/src/enum/index.js +6 -0
- package/dist/src/enum/index.js.map +1 -0
- package/dist/src/interfaces/corporates-options.interface.d.ts +6 -0
- package/dist/src/interfaces/corporates-options.interface.js +3 -0
- package/dist/src/interfaces/corporates-options.interface.js.map +1 -0
- package/dist/src/mappers/corporate.mapper.d.ts +6 -0
- package/dist/src/mappers/corporate.mapper.js +31 -0
- package/dist/src/mappers/corporate.mapper.js.map +1 -0
- package/dist/src/migrations/1756375671676-CreateRelCorporateUserTable.d.ts +6 -0
- package/dist/src/migrations/1756375671676-CreateRelCorporateUserTable.js +48 -0
- package/dist/src/migrations/1756375671676-CreateRelCorporateUserTable.js.map +1 -0
- package/dist/src/migrations/1756375695674-CreateCorporateTable.d.ts +6 -0
- package/dist/src/migrations/1756375695674-CreateCorporateTable.js +51 -0
- package/dist/src/migrations/1756375695674-CreateCorporateTable.js.map +1 -0
- package/dist/src/migrations/1756375696676-CreateRelCorporateParticipantTable.d.ts +6 -0
- package/dist/src/migrations/1756375696676-CreateRelCorporateParticipantTable.js +48 -0
- package/dist/src/migrations/1756375696676-CreateRelCorporateParticipantTable.js.map +1 -0
- package/dist/src/migrations/index.d.ts +4 -0
- package/dist/src/migrations/index.js +12 -0
- package/dist/src/migrations/index.js.map +1 -0
- package/dist/src/modules/corporate.module.d.ts +5 -0
- package/dist/src/modules/corporate.module.js +35 -0
- package/dist/src/modules/corporate.module.js.map +1 -0
- package/dist/src/repository/base.repository.d.ts +9 -0
- package/dist/src/repository/base.repository.js +29 -0
- package/dist/src/repository/base.repository.js.map +1 -0
- package/dist/src/repository/corporate.repository.d.ts +4 -0
- package/dist/src/repository/corporate.repository.js +8 -0
- package/dist/src/repository/corporate.repository.js.map +1 -0
- package/dist/src/repository/index.d.ts +1 -0
- package/dist/src/repository/index.js +18 -0
- package/dist/src/repository/index.js.map +1 -0
- package/dist/src/services/corporate.service.d.ts +22 -0
- package/dist/src/services/corporate.service.js +111 -0
- package/dist/src/services/corporate.service.js.map +1 -0
- package/dist/src/services/index.d.ts +2 -0
- package/dist/src/services/index.js +6 -0
- package/dist/src/services/index.js.map +1 -0
- package/dist/src/test/corporate-criteria.service.spec.d.ts +1 -0
- package/dist/src/test/corporate-criteria.service.spec.js +17 -0
- package/dist/src/test/corporate-criteria.service.spec.js.map +1 -0
- package/dist/src/utilities/index.d.ts +2 -0
- package/dist/src/utilities/index.js +6 -0
- package/dist/src/utilities/index.js.map +1 -0
- package/dist/src/utilities/migrations/get-base-columns.d.ts +2 -0
- package/dist/src/utilities/migrations/get-base-columns.js +34 -0
- package/dist/src/utilities/migrations/get-base-columns.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/index.ts +29 -0
- package/jest.config.ts +10 -0
- package/nest-cli.json +8 -0
- package/package.json +53 -0
- package/src/constants/corporates-options.ts +1 -0
- package/src/constants/index.ts +1 -0
- package/src/dto/base.dto.ts +14 -0
- package/src/dto/corporate.dto.ts +27 -0
- package/src/dto/index.ts +6 -0
- package/src/dto/rel-corporate-user.dto.ts +0 -0
- package/src/entities/base.entity.ts +23 -0
- package/src/entities/corporate.entity.ts +24 -0
- package/src/entities/index.ts +4 -0
- package/src/entities/pagination.ts +42 -0
- package/src/entities/rel-corporate-user.entity.ts +15 -0
- package/src/enum/corporate-status.enum.ts +4 -0
- package/src/enum/index.ts +1 -0
- package/src/interfaces/corporates-options.interface.ts +6 -0
- package/src/mappers/corporate.mapper.ts +36 -0
- package/src/migrations/1756375695674-CreateCorporateTable.ts +50 -0
- package/src/migrations/1756375696676-CreateRelCorporateParticipantTable.ts +48 -0
- package/src/migrations/index.ts +12 -0
- package/src/modules/corporate.module.ts +23 -0
- package/src/repository/base.repository.ts +42 -0
- package/src/repository/corporate.repository.ts +4 -0
- package/src/repository/index.ts +1 -0
- package/src/services/corporate.service.ts +142 -0
- package/src/services/index.ts +5 -0
- package/src/test/corporate-criteria.service.spec.ts +20 -0
- package/src/utilities/index.ts +5 -0
- package/src/utilities/migrations/get-base-columns.ts +32 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +21 -0
package/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//MODULES
|
|
2
|
+
export * from './src/modules/corporate.module';
|
|
3
|
+
|
|
4
|
+
//INTERFACES
|
|
5
|
+
export * from './src/interfaces/corporates-options.interface';
|
|
6
|
+
|
|
7
|
+
//SERVICES
|
|
8
|
+
export * from './src/services';
|
|
9
|
+
|
|
10
|
+
//ENTITIES
|
|
11
|
+
export * from './src/entities';
|
|
12
|
+
|
|
13
|
+
//ENUMS
|
|
14
|
+
export * from './src/enum';
|
|
15
|
+
|
|
16
|
+
//DTOS
|
|
17
|
+
export * from './src/dto';
|
|
18
|
+
|
|
19
|
+
//CONSTANTS
|
|
20
|
+
export * from './src/constants';
|
|
21
|
+
|
|
22
|
+
//MIGRATIONS
|
|
23
|
+
export * from './src/migrations';
|
|
24
|
+
|
|
25
|
+
//REPOSITORIES
|
|
26
|
+
export * from './src/repository';
|
|
27
|
+
|
|
28
|
+
//UTILITIES
|
|
29
|
+
export * from './src/utilities';
|
package/jest.config.ts
ADDED
package/nest-cli.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dirayaah/corporate-module",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "1.0.17",
|
|
7
|
+
"description": "A reusable module for handling Corporates in nestjs applications",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"type": "commonjs",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./migrations": {
|
|
16
|
+
"import": "./dist/migrations/index.js",
|
|
17
|
+
"require": "./dist/migrations/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./entities": {
|
|
20
|
+
"import": "./dist/entities/index.js",
|
|
21
|
+
"require": "./dist/entities/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://gitlab.zadapps.info/dirayaah/packages/corporate.git"
|
|
31
|
+
},
|
|
32
|
+
"author": "MD-LABS",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@nestjs/common": "^10.4.20",
|
|
36
|
+
"@nestjs/core": "^10.4.20",
|
|
37
|
+
"@nestjs/platform-express": "^10.4.20",
|
|
38
|
+
"@nestjs/swagger": "^7.4.2",
|
|
39
|
+
"@nestjs/typeorm": "^10.0.2",
|
|
40
|
+
"class-transformer": "^0.5.1",
|
|
41
|
+
"class-validator": "^0.14.3",
|
|
42
|
+
"typeorm": "^0.3.28"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@nestjs/testing": "^10.4.16",
|
|
46
|
+
"@types/express": "^4.17.21",
|
|
47
|
+
"@types/jest": "^28.1.8",
|
|
48
|
+
"@types/node": "^20.14.0",
|
|
49
|
+
"jest": "^28.1.3",
|
|
50
|
+
"ts-jest": "^28.0.8",
|
|
51
|
+
"typescript": "^5.3.3"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CORPORATES_OPTIONS = 'CORPORATES_OPTIONS';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CORPORATES_OPTIONS } from './corporates-options';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IsNotEmpty, IsEnum, IsOptional } from 'class-validator';
|
|
2
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
3
|
+
import { BaseDTO } from './base.dto';
|
|
4
|
+
|
|
5
|
+
export class CorporateDto extends BaseDTO {
|
|
6
|
+
@IsNotEmpty()
|
|
7
|
+
@ApiProperty({ type: String, required: true, name: 'name' })
|
|
8
|
+
name: string;
|
|
9
|
+
|
|
10
|
+
@IsNotEmpty()
|
|
11
|
+
@ApiProperty({ type: Number, required: true, name: 'managerId' })
|
|
12
|
+
managerId: number;
|
|
13
|
+
|
|
14
|
+
@IsOptional()
|
|
15
|
+
@ApiProperty({ type: String, required: false, name: 'email' })
|
|
16
|
+
email?: string;
|
|
17
|
+
|
|
18
|
+
@ApiProperty({
|
|
19
|
+
name: 'status',
|
|
20
|
+
description: 'Corporate status',
|
|
21
|
+
})
|
|
22
|
+
status: string;
|
|
23
|
+
|
|
24
|
+
@IsOptional()
|
|
25
|
+
@ApiProperty({ type: Number, required: false, name: 'maxParticipantsCount' })
|
|
26
|
+
maxParticipantsCount?: number;
|
|
27
|
+
}
|
package/src/dto/index.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PrimaryGeneratedColumn,
|
|
3
|
+
Column,
|
|
4
|
+
CreateDateColumn,
|
|
5
|
+
UpdateDateColumn,
|
|
6
|
+
} from 'typeorm';
|
|
7
|
+
|
|
8
|
+
export abstract class BaseEntity {
|
|
9
|
+
@PrimaryGeneratedColumn()
|
|
10
|
+
id?: number;
|
|
11
|
+
|
|
12
|
+
@Column({ nullable: true })
|
|
13
|
+
createdBy?: string;
|
|
14
|
+
|
|
15
|
+
@CreateDateColumn({ nullable: true })
|
|
16
|
+
createdDate?: Date;
|
|
17
|
+
|
|
18
|
+
@Column({ nullable: true })
|
|
19
|
+
lastModifiedBy?: string;
|
|
20
|
+
|
|
21
|
+
@UpdateDateColumn({ nullable: true })
|
|
22
|
+
lastModifiedDate?: Date;
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseEntity } from './base.entity';
|
|
2
|
+
import { Column, Entity, OneToMany } from 'typeorm';
|
|
3
|
+
import { RelCorporateParticipantsEntity } from './rel-corporate-user.entity';
|
|
4
|
+
|
|
5
|
+
@Entity('corporate')
|
|
6
|
+
export class CorporateEntity extends BaseEntity {
|
|
7
|
+
@Column({ nullable: false })
|
|
8
|
+
name: string;
|
|
9
|
+
|
|
10
|
+
@Column({ nullable: true })
|
|
11
|
+
email: string;
|
|
12
|
+
|
|
13
|
+
@Column({ nullable: false })
|
|
14
|
+
managerId: number;
|
|
15
|
+
|
|
16
|
+
@Column({ nullable: true })
|
|
17
|
+
status: string;
|
|
18
|
+
|
|
19
|
+
@Column({ nullable: true, name: 'max_participants_count' })
|
|
20
|
+
maxParticipantsCount: number;
|
|
21
|
+
|
|
22
|
+
@OneToMany(() => RelCorporateParticipantsEntity, (rel) => rel.corporate)
|
|
23
|
+
relCorporateParticipants: RelCorporateParticipantsEntity[];
|
|
24
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
|
2
|
+
import { Type, Expose as JsonProperty } from 'class-transformer';
|
|
3
|
+
import { BaseEntity } from './base.entity';
|
|
4
|
+
|
|
5
|
+
export class Sort {
|
|
6
|
+
public property: string;
|
|
7
|
+
public direction: 'ASC' | 'DESC' | string;
|
|
8
|
+
constructor(sort: string) {
|
|
9
|
+
if (sort) {
|
|
10
|
+
[this.property, this.direction] = sort.split(',');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
asOrder(): any {
|
|
15
|
+
const order = {};
|
|
16
|
+
order[this.property] = this.direction;
|
|
17
|
+
return order;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class PageRequest {
|
|
22
|
+
@JsonProperty()
|
|
23
|
+
page: number = 0;
|
|
24
|
+
@JsonProperty()
|
|
25
|
+
size: number = 20;
|
|
26
|
+
@Type(() => Sort)
|
|
27
|
+
sort: Sort = new Sort('id,ASC');
|
|
28
|
+
|
|
29
|
+
constructor(page: number | string, size: number | string, sort: string) {
|
|
30
|
+
this.page = +page || this.page;
|
|
31
|
+
this.size = +size || this.size;
|
|
32
|
+
this.sort = sort ? new Sort(sort) : this.sort;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class Page<T extends BaseEntity> {
|
|
37
|
+
constructor(
|
|
38
|
+
public content: T[],
|
|
39
|
+
public total: number,
|
|
40
|
+
public pageable: PageRequest,
|
|
41
|
+
) {}
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseEntity } from './base.entity';
|
|
2
|
+
import { Column, Entity, ManyToOne } from 'typeorm';
|
|
3
|
+
import { CorporateEntity } from './corporate.entity';
|
|
4
|
+
|
|
5
|
+
@Entity('rel_corporate_participant')
|
|
6
|
+
export class RelCorporateParticipantsEntity extends BaseEntity {
|
|
7
|
+
@ManyToOne(
|
|
8
|
+
() => CorporateEntity,
|
|
9
|
+
(corporate) => corporate.relCorporateParticipants,
|
|
10
|
+
)
|
|
11
|
+
corporate: CorporateEntity;
|
|
12
|
+
|
|
13
|
+
@Column({ nullable: false })
|
|
14
|
+
participantId: number;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CorporateStatus } from './corporate-status.enum';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CorporateDto } from '../dto/corporate.dto';
|
|
2
|
+
import { CorporateEntity } from '../entities';
|
|
3
|
+
|
|
4
|
+
export class CorporateMapper {
|
|
5
|
+
|
|
6
|
+
static fromDTOToEntity(corporateDto: CorporateDto): CorporateEntity {
|
|
7
|
+
if (!corporateDto) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let corporateEntity = new CorporateEntity();
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const fields = Object.getOwnPropertyNames(corporateDto);
|
|
14
|
+
|
|
15
|
+
fields.forEach((field) => {
|
|
16
|
+
corporateEntity[field] = corporateDto[field];
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return corporateEntity;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static fromEntityToDTO(entity: CorporateEntity): CorporateDto {
|
|
23
|
+
if (!entity) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
let entityDTO = new CorporateDto();
|
|
27
|
+
|
|
28
|
+
const fields = Object.getOwnPropertyNames(entity);
|
|
29
|
+
|
|
30
|
+
fields.forEach((field) => {
|
|
31
|
+
entityDTO[field] = entity[field];
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return entityDTO;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { baseColumns } from '../utilities';
|
|
2
|
+
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
|
|
3
|
+
import { CorporateStatus } from '../enum/corporate-status.enum';
|
|
4
|
+
|
|
5
|
+
export class CreateCorporateTable1756375695674 implements MigrationInterface {
|
|
6
|
+
private readonly table = 'corporate';
|
|
7
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
8
|
+
const [idColumn, ...otherBaseColumns] = baseColumns;
|
|
9
|
+
await queryRunner.createTable(
|
|
10
|
+
new Table({
|
|
11
|
+
name: this.table,
|
|
12
|
+
columns: [
|
|
13
|
+
idColumn,
|
|
14
|
+
{
|
|
15
|
+
name: 'name',
|
|
16
|
+
type: 'varchar',
|
|
17
|
+
isNullable: false,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'managerId',
|
|
21
|
+
type: 'int4',
|
|
22
|
+
isNullable: false,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'email',
|
|
26
|
+
type: 'varchar',
|
|
27
|
+
isNullable: true,
|
|
28
|
+
isUnique: true,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'status',
|
|
32
|
+
type: 'varchar',
|
|
33
|
+
isNullable: false,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'max_participants_count',
|
|
37
|
+
type: 'int4',
|
|
38
|
+
isNullable: true,
|
|
39
|
+
},
|
|
40
|
+
...otherBaseColumns,
|
|
41
|
+
],
|
|
42
|
+
}),
|
|
43
|
+
false,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
48
|
+
await queryRunner.dropTable(this.table, true, true, true);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { baseColumns } from '../utilities';
|
|
2
|
+
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
|
|
3
|
+
|
|
4
|
+
export class CreateRelCorporateParticipantTable1756375696676
|
|
5
|
+
implements MigrationInterface
|
|
6
|
+
{
|
|
7
|
+
private readonly table = 'rel_corporate_participant';
|
|
8
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
9
|
+
const [idColumn, ...otherBaseColumns] = baseColumns;
|
|
10
|
+
await queryRunner.createTable(
|
|
11
|
+
new Table({
|
|
12
|
+
name: this.table,
|
|
13
|
+
columns: [
|
|
14
|
+
idColumn,
|
|
15
|
+
{
|
|
16
|
+
name: 'corporateId',
|
|
17
|
+
type: 'int4',
|
|
18
|
+
isNullable: false,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'participantId',
|
|
22
|
+
type: 'int4',
|
|
23
|
+
isNullable: false,
|
|
24
|
+
},
|
|
25
|
+
...otherBaseColumns,
|
|
26
|
+
],
|
|
27
|
+
foreignKeys: [
|
|
28
|
+
{
|
|
29
|
+
name: `fk_${this.table}_corporate`,
|
|
30
|
+
columnNames: ['corporateId'],
|
|
31
|
+
referencedTableName: 'corporate',
|
|
32
|
+
referencedColumnNames: ['id'],
|
|
33
|
+
onDelete: 'CASCADE',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
uniques: [
|
|
37
|
+
{
|
|
38
|
+
name: `UQ_${this.table}_corporateId_participantId`,
|
|
39
|
+
columnNames: ['corporateId', 'participantId'],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
}),
|
|
43
|
+
false,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public async down(queryRunner: QueryRunner): Promise<void> {}
|
|
48
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CreateCorporateTable1756375695674 } from './1756375695674-CreateCorporateTable';
|
|
2
|
+
import { CreateRelCorporateParticipantTable1756375696676 } from './1756375696676-CreateRelCorporateParticipantTable';
|
|
3
|
+
|
|
4
|
+
export const CorporateMigrations = [
|
|
5
|
+
CreateCorporateTable1756375695674,
|
|
6
|
+
CreateRelCorporateParticipantTable1756375696676,
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
CreateCorporateTable1756375695674,
|
|
11
|
+
CreateRelCorporateParticipantTable1756375696676,
|
|
12
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DynamicModule, Module } from '@nestjs/common';
|
|
2
|
+
import { CORPORATES_OPTIONS } from '../constants/corporates-options';
|
|
3
|
+
import { CorporateModuleOptions } from '../interfaces/corporates-options.interface';
|
|
4
|
+
import { CorporateService } from '../services';
|
|
5
|
+
|
|
6
|
+
@Module({})
|
|
7
|
+
export class CorporateModule {
|
|
8
|
+
static forRoot(options: CorporateModuleOptions): DynamicModule {
|
|
9
|
+
return {
|
|
10
|
+
module: CorporateModule,
|
|
11
|
+
providers: [
|
|
12
|
+
{
|
|
13
|
+
provide: CORPORATES_OPTIONS,
|
|
14
|
+
useValue: options,
|
|
15
|
+
},
|
|
16
|
+
CorporateService,
|
|
17
|
+
],
|
|
18
|
+
exports: [
|
|
19
|
+
CorporateService,
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Repository,
|
|
3
|
+
DeepPartial,
|
|
4
|
+
FindManyOptions,
|
|
5
|
+
FindOneOptions,
|
|
6
|
+
} from 'typeorm';
|
|
7
|
+
import { BaseEntity } from '../entities/base.entity';
|
|
8
|
+
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
|
|
9
|
+
|
|
10
|
+
export abstract class BaseRepository<
|
|
11
|
+
T extends BaseEntity,
|
|
12
|
+
> extends Repository<T> {
|
|
13
|
+
async findById(id: number | string): Promise<T | undefined> {
|
|
14
|
+
return this.findOne({ where: { id } } as FindOneOptions<T>);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async findWithOptions(options: FindManyOptions<T>): Promise<[T[], number]> {
|
|
18
|
+
return this.findAndCount(options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async createEntity(data: DeepPartial<T>, creator?: string): Promise<T> {
|
|
22
|
+
const entity = this.create(data);
|
|
23
|
+
if (creator) {
|
|
24
|
+
entity.createdBy = creator;
|
|
25
|
+
entity.lastModifiedBy = creator;
|
|
26
|
+
}
|
|
27
|
+
return this.save(entity as DeepPartial<T>);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async updateEntity(
|
|
31
|
+
id: number | string,
|
|
32
|
+
data: QueryDeepPartialEntity<T>,
|
|
33
|
+
updater?: string,
|
|
34
|
+
): Promise<T | undefined> {
|
|
35
|
+
await this.update(id, {
|
|
36
|
+
...data,
|
|
37
|
+
lastModifiedBy: updater,
|
|
38
|
+
} as QueryDeepPartialEntity<T>);
|
|
39
|
+
|
|
40
|
+
return this.findById(id);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './corporate.repository';
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BadRequestException,
|
|
3
|
+
Inject,
|
|
4
|
+
Injectable,
|
|
5
|
+
NotFoundException,
|
|
6
|
+
} from '@nestjs/common';
|
|
7
|
+
import { FindManyOptions, FindOneOptions, Repository } from 'typeorm';
|
|
8
|
+
import { CorporateEntity } from '../entities/corporate.entity';
|
|
9
|
+
import { CorporateModuleOptions } from '../interfaces/corporates-options.interface';
|
|
10
|
+
import { CORPORATES_OPTIONS } from '../constants/corporates-options';
|
|
11
|
+
import { CorporateDto } from '../dto/corporate.dto';
|
|
12
|
+
import { PageRequest } from '../entities/pagination';
|
|
13
|
+
import { CorporateMapper } from '../mappers/corporate.mapper';
|
|
14
|
+
|
|
15
|
+
@Injectable()
|
|
16
|
+
export class CorporateService {
|
|
17
|
+
constructor(
|
|
18
|
+
@Inject(CORPORATES_OPTIONS)
|
|
19
|
+
private readonly options: CorporateModuleOptions,
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
private async getRepository(
|
|
23
|
+
tenantId: string,
|
|
24
|
+
): Promise<Repository<CorporateEntity>> {
|
|
25
|
+
const connection =
|
|
26
|
+
await this.options.connectionProvider.getTenantConnection(tenantId);
|
|
27
|
+
return connection.getRepository(CorporateEntity);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private async validateUniqueCorporateProps(
|
|
31
|
+
createCorporateDto: CorporateDto,
|
|
32
|
+
tenantId: string,
|
|
33
|
+
) {
|
|
34
|
+
const corporate = await this.findOneByOptions(
|
|
35
|
+
{
|
|
36
|
+
where: { email: createCorporateDto.email },
|
|
37
|
+
},
|
|
38
|
+
tenantId,
|
|
39
|
+
);
|
|
40
|
+
if (corporate) {
|
|
41
|
+
throw new BadRequestException('CORPORATE_EMAIL_ALREADY_EXISTS');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async create(createCorporateDto: CorporateDto, tenantId: string) {
|
|
46
|
+
await this.validateUniqueCorporateProps(createCorporateDto, tenantId);
|
|
47
|
+
|
|
48
|
+
const repository = await this.getRepository(tenantId);
|
|
49
|
+
|
|
50
|
+
const corporateEntity = CorporateMapper.fromDTOToEntity(createCorporateDto);
|
|
51
|
+
|
|
52
|
+
return repository.save(corporateEntity);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async findAll(tenantId: string): Promise<CorporateDto[]> {
|
|
56
|
+
const repository = await this.getRepository(tenantId);
|
|
57
|
+
const corporates = await repository
|
|
58
|
+
.createQueryBuilder('corporate')
|
|
59
|
+
.getMany();
|
|
60
|
+
return corporates.map((corporate) =>
|
|
61
|
+
CorporateMapper.fromEntityToDTO(corporate),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async findByOptions(
|
|
66
|
+
options: FindManyOptions<CorporateEntity>,
|
|
67
|
+
tenantId: string,
|
|
68
|
+
): Promise<CorporateDto[]> {
|
|
69
|
+
const repository = await this.getRepository(tenantId);
|
|
70
|
+
const corporates = await repository.find(options);
|
|
71
|
+
return corporates.map((corporate) =>
|
|
72
|
+
CorporateMapper.fromEntityToDTO(corporate),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async findOne(id: number, tenantId: string): Promise<CorporateDto> {
|
|
77
|
+
const repository = await this.getRepository(tenantId);
|
|
78
|
+
|
|
79
|
+
const corporate = await repository
|
|
80
|
+
.createQueryBuilder('corporate')
|
|
81
|
+
.where('corporate.id = :id', { id })
|
|
82
|
+
.getOne();
|
|
83
|
+
|
|
84
|
+
return CorporateMapper.fromEntityToDTO(corporate);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async findOneByOptions(
|
|
88
|
+
options: FindOneOptions<CorporateEntity>,
|
|
89
|
+
tenantId: string,
|
|
90
|
+
): Promise<CorporateDto> {
|
|
91
|
+
const repository = await this.getRepository(tenantId);
|
|
92
|
+
const corporate = await repository.findOne(options);
|
|
93
|
+
return CorporateMapper.fromEntityToDTO(corporate);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async getPaginatedCorporates(
|
|
97
|
+
pageRequest: PageRequest,
|
|
98
|
+
tenantId: string,
|
|
99
|
+
): Promise<{ result: CorporateDto[]; totalCount: number }> {
|
|
100
|
+
const repository = await this.getRepository(tenantId);
|
|
101
|
+
const corporates = await repository
|
|
102
|
+
.createQueryBuilder('corporate')
|
|
103
|
+
.skip(pageRequest.page * pageRequest.size)
|
|
104
|
+
.take(pageRequest.size)
|
|
105
|
+
.orderBy('corporate.id', 'DESC')
|
|
106
|
+
.getMany();
|
|
107
|
+
|
|
108
|
+
const totalCount = await repository.count();
|
|
109
|
+
return {
|
|
110
|
+
result: corporates.map((corporate) =>
|
|
111
|
+
CorporateMapper.fromEntityToDTO(corporate),
|
|
112
|
+
),
|
|
113
|
+
totalCount,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async update(updateCorporateDto: CorporateDto, tenantId: string) {
|
|
118
|
+
const repository = await this.getRepository(tenantId);
|
|
119
|
+
const existingCorporate = await repository.findOne({
|
|
120
|
+
where: { id: updateCorporateDto.id },
|
|
121
|
+
});
|
|
122
|
+
if (!existingCorporate) {
|
|
123
|
+
throw new NotFoundException('CORPORATE_DOES_NOT_EXIST');
|
|
124
|
+
}
|
|
125
|
+
if (updateCorporateDto.email && existingCorporate.email !== updateCorporateDto.email) {
|
|
126
|
+
const existingCorporateWithNewData = await repository.findOne({
|
|
127
|
+
where: { email: updateCorporateDto.email },
|
|
128
|
+
});
|
|
129
|
+
if (existingCorporateWithNewData) {
|
|
130
|
+
throw new BadRequestException('CORPORATE_EMAIL_ALREADY_EXISTS');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const updateCorporateEntity =
|
|
134
|
+
CorporateMapper.fromDTOToEntity(updateCorporateDto);
|
|
135
|
+
return repository.update(updateCorporateDto.id, updateCorporateEntity);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async remove(id: number, tenantId: string) {
|
|
139
|
+
const repository = await this.getRepository(tenantId);
|
|
140
|
+
return await repository.delete(id);
|
|
141
|
+
}
|
|
142
|
+
}
|