Skip to content

Commit 22fa293

Browse files
committed
WIP schemas + dto (core)
1 parent e40d511 commit 22fa293

File tree

22 files changed

+299
-43
lines changed

22 files changed

+299
-43
lines changed

service/src/core/categories/_schemas/categories.schema.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ export class Categories extends AbstractSchema {
2929
public order: number
3030

3131
@Prop({
32-
required: true,
3332
type: Boolean,
3433
default: true,
3534
})
3635
public selectable: boolean
3736

3837
@Prop({
39-
required: true,
4038
type: Boolean,
4139
default: false,
4240
})

service/src/core/categories/categories.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class CategoriesController extends AbstractController {
2828
parentId: 1,
2929
description: 1,
3030
color: 1,
31-
icon: 0,
31+
icon: 1,
3232
}
3333

3434
constructor(private readonly _service: CategoriesService) {

service/src/core/entities/_dto/entites.dto.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1-
import { PartialType } from '@nestjs/swagger'
1+
import { ApiProperty, PartialType } from '@nestjs/swagger'
2+
import { AbstractCustomFieldsDto } from '~/_common/abstracts/dto/abstract.custom-fields.dto'
3+
import { Type } from 'class-transformer'
4+
import { IsMongoId, IsNotEmpty, IsOptional, IsString, ValidateNested } from 'class-validator'
5+
import { ProfilePartDto } from '~/core/entities/_dto/parts/profile.part.dto'
6+
import { StatePartDto } from '~/core/entities/_dto/parts/state.part.dto'
27

3-
export class EntitiesCreateDto {
8+
export class EntitiesCreateDto extends AbstractCustomFieldsDto {
9+
@IsString()
10+
@IsNotEmpty()
11+
@ApiProperty()
12+
public publicEmail: string
413

14+
@ValidateNested()
15+
@Type(() => ProfilePartDto)
16+
@IsNotEmpty()
17+
@ApiProperty()
18+
public profile: ProfilePartDto
19+
20+
@ValidateNested()
21+
@Type(() => StatePartDto)
22+
@IsOptional()
23+
@ApiProperty()
24+
public state?: StatePartDto
25+
}
26+
27+
export class EntitiesDto extends EntitiesCreateDto {
28+
@IsMongoId()
29+
@ApiProperty()
30+
public _id: string
531
}
632

733
export class EntitiesUpdateDto extends PartialType(EntitiesCreateDto) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { PhoneType, PhoneTypeList } from '~/core/entities/_enum/phone-type.enum'
2+
import { IsEnum, IsNotEmpty, IsOptional, IsString, IsPhoneNumber } from 'class-validator'
3+
import { ApiProperty } from '@nestjs/swagger'
4+
5+
export class PhonePartDto {
6+
@IsEnum(PhoneTypeList)
7+
@IsNotEmpty()
8+
@ApiProperty({ enum: PhoneTypeList })
9+
public type: PhoneType
10+
11+
@IsString()
12+
@IsPhoneNumber()
13+
@IsNotEmpty()
14+
@ApiProperty()
15+
public phoneNumber: string
16+
17+
@IsString()
18+
@IsOptional()
19+
@ApiProperty()
20+
public description?: string
21+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { IsNotEmpty, IsOptional, IsString, ValidateNested } from 'class-validator'
2+
import { PhonePartDto } from '~/core/entities/_dto/parts/phone.part.dto'
3+
import { Type } from 'class-transformer'
4+
import { ApiProperty } from '@nestjs/swagger'
5+
6+
export class ProfilePartDto {
7+
@IsString()
8+
@IsNotEmpty()
9+
@ApiProperty()
10+
public commonName: string
11+
12+
@IsString()
13+
@IsOptional()
14+
@ApiProperty()
15+
public firstName?: string
16+
17+
@IsString()
18+
@IsOptional()
19+
@ApiProperty()
20+
public lastName?: string
21+
22+
@IsString()
23+
@IsOptional()
24+
@ApiProperty()
25+
public thirdName?: string
26+
27+
@IsString()
28+
@IsOptional()
29+
@ApiProperty()
30+
public avatar?: string
31+
32+
@ValidateNested({ each: true })
33+
@Type(() => PhonePartDto)
34+
@IsOptional()
35+
@ApiProperty({ type: [PhonePartDto] })
36+
public phones?: PhonePartDto[]
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { IsEnum, IsNotEmpty, IsOptional, IsDate } from 'class-validator'
2+
import { EntityState, EntityStateList } from '~/core/entities/_enum/entity-state.enum'
3+
import { ApiProperty } from '@nestjs/swagger'
4+
5+
export class StatePartDto {
6+
@IsEnum(EntityStateList)
7+
@IsNotEmpty()
8+
@ApiProperty({ enum: EntityStateList })
9+
public current: EntityState
10+
11+
@IsDate()
12+
@IsOptional()
13+
@ApiProperty()
14+
public lastChangedAt?: Date
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export enum EntityType {
2+
AGENT = 1,
3+
CONTACT = 2,
4+
CLIENT = 3,
5+
COMPANY = 4,
6+
}
7+
8+
export const EntityTypeList: number[] = Object.keys(EntityType)
9+
.filter((k) => typeof EntityType[k as any] === 'number')
10+
.map((k) => parseInt(EntityType[k as any], 10))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export enum PhoneType {
2+
OTHER = 1,
3+
HOME = 2,
4+
PROFESSIONAL = 3,
5+
PERSONAL = 4,
6+
FAX = 5,
7+
}
8+
9+
export const PhoneTypeList: number[] = Object.keys(PhoneType)
10+
.filter((k) => typeof PhoneType[k as any] === 'number')
11+
.map((k) => parseInt(PhoneType[k as any], 10))

service/src/core/entities/_schemas/entities.schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class Entity extends AbstractSchema {
1111
@Prop({
1212
type: String,
1313
required: true,
14+
unique: true,
1415
})
1516
public publicEmail: string
1617

@@ -22,7 +23,7 @@ export class Entity extends AbstractSchema {
2223

2324
@Prop({
2425
type: StatePartSchema,
25-
required: true,
26+
default: {},
2627
})
2728
public state: StatePart
2829

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2+
import { Document } from 'mongoose'
3+
import { EntityState, EntityStateList } from '~/core/entities/_enum/entity-state.enum'
4+
import { ProfilePart } from '~/core/entities/_schemas/parts/profile.part.schema'
5+
import { PhoneType, PhoneTypeList } from '~/core/entities/_enum/phone-type.enum'
6+
7+
@Schema({ _id: false })
8+
export class PhonePart extends Document {
9+
@Prop({
10+
type: Number,
11+
enum: PhoneTypeList,
12+
required: true,
13+
})
14+
public type: PhoneType
15+
16+
@Prop({
17+
type: String,
18+
required: true,
19+
})
20+
public phoneNumber: string
21+
22+
@Prop({
23+
type: String,
24+
})
25+
public description: string
26+
}
27+
28+
export const PhonePartSchema = SchemaFactory.createForClass(PhonePart)

0 commit comments

Comments
 (0)