Skip to content

Commit f3a9db6

Browse files
Merge pull request #487 from Breedar/assetsDto
Data transfer objects
2 parents bfac0ac + e6562c9 commit f3a9db6

File tree

9 files changed

+281
-0
lines changed

9 files changed

+281
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { ApiPropertyOptional } from '@nestjs/swagger';
2+
import { IsOptional, IsEnum, IsString, IsNumber, Min } from 'class-validator';
3+
import { Type } from 'class-transformer';
4+
import { AssetStatus, AssetCondition } from '../enums';
5+
6+
export class AssetFiltersDto {
7+
@ApiPropertyOptional()
8+
@IsString()
9+
@IsOptional()
10+
search?: string;
11+
12+
@ApiPropertyOptional({ enum: AssetStatus })
13+
@IsEnum(AssetStatus)
14+
@IsOptional()
15+
status?: AssetStatus;
16+
17+
@ApiPropertyOptional({ enum: AssetCondition })
18+
@IsEnum(AssetCondition)
19+
@IsOptional()
20+
condition?: AssetCondition;
21+
22+
@ApiPropertyOptional()
23+
@IsString()
24+
@IsOptional()
25+
categoryId?: string;
26+
27+
@ApiPropertyOptional()
28+
@IsString()
29+
@IsOptional()
30+
departmentId?: string;
31+
32+
@ApiPropertyOptional({ default: 1 })
33+
@IsNumber()
34+
@Min(1)
35+
@IsOptional()
36+
@Type(() => Number)
37+
page?: number = 1;
38+
39+
@ApiPropertyOptional({ default: 20 })
40+
@IsNumber()
41+
@Min(1)
42+
@IsOptional()
43+
@Type(() => Number)
44+
limit?: number = 20;
45+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2+
import {
3+
IsString,
4+
IsNotEmpty,
5+
IsOptional,
6+
IsUUID,
7+
IsEnum,
8+
IsNumber,
9+
IsDateString,
10+
IsArray,
11+
MaxLength,
12+
Min,
13+
} from 'class-validator';
14+
import { Type } from 'class-transformer';
15+
import { AssetStatus, AssetCondition } from '../enums';
16+
17+
export class CreateAssetDto {
18+
@ApiProperty({ example: 'MacBook Pro 16"' })
19+
@IsString()
20+
@IsNotEmpty()
21+
@MaxLength(255)
22+
name: string;
23+
24+
@ApiPropertyOptional()
25+
@IsString()
26+
@IsOptional()
27+
@MaxLength(2000)
28+
description?: string;
29+
30+
@ApiProperty({ example: 'uuid-of-category' })
31+
@IsUUID()
32+
categoryId: string;
33+
34+
@ApiProperty({ example: 'uuid-of-department' })
35+
@IsUUID()
36+
departmentId: string;
37+
38+
@ApiPropertyOptional({ example: 'SN-12345' })
39+
@IsString()
40+
@IsOptional()
41+
@MaxLength(100)
42+
serialNumber?: string;
43+
44+
@ApiPropertyOptional({ example: '2024-01-15' })
45+
@IsDateString()
46+
@IsOptional()
47+
purchaseDate?: string;
48+
49+
@ApiPropertyOptional({ example: 2500 })
50+
@IsNumber()
51+
@Min(0)
52+
@IsOptional()
53+
@Type(() => Number)
54+
purchasePrice?: number;
55+
56+
@ApiPropertyOptional({ example: 2000 })
57+
@IsNumber()
58+
@Min(0)
59+
@IsOptional()
60+
@Type(() => Number)
61+
currentValue?: number;
62+
63+
@ApiPropertyOptional({ example: '2026-01-15' })
64+
@IsDateString()
65+
@IsOptional()
66+
warrantyExpiration?: string;
67+
68+
@ApiPropertyOptional({ enum: AssetStatus, default: AssetStatus.ACTIVE })
69+
@IsEnum(AssetStatus)
70+
@IsOptional()
71+
status?: AssetStatus;
72+
73+
@ApiPropertyOptional({ enum: AssetCondition, default: AssetCondition.NEW })
74+
@IsEnum(AssetCondition)
75+
@IsOptional()
76+
condition?: AssetCondition;
77+
78+
@ApiPropertyOptional({ example: 'Floor 2, Room 204' })
79+
@IsString()
80+
@IsOptional()
81+
@MaxLength(255)
82+
location?: string;
83+
84+
@ApiPropertyOptional({ example: 'uuid-of-user' })
85+
@IsUUID()
86+
@IsOptional()
87+
assignedToId?: string;
88+
89+
@ApiPropertyOptional({ example: 'Apple' })
90+
@IsString()
91+
@IsOptional()
92+
@MaxLength(100)
93+
manufacturer?: string;
94+
95+
@ApiPropertyOptional({ example: 'MacBook Pro' })
96+
@IsString()
97+
@IsOptional()
98+
@MaxLength(100)
99+
model?: string;
100+
101+
@ApiPropertyOptional({ example: ['laptop', 'engineering'] })
102+
@IsArray()
103+
@IsString({ each: true })
104+
@IsOptional()
105+
tags?: string[];
106+
107+
@ApiPropertyOptional()
108+
@IsString()
109+
@IsOptional()
110+
@MaxLength(2000)
111+
notes?: string;
112+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { IsString, IsNotEmpty, IsOptional, IsNumber } from 'class-validator';
2+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
3+
4+
export class CreateDocumentDto {
5+
@ApiProperty()
6+
@IsString()
7+
@IsNotEmpty()
8+
name: string;
9+
10+
@ApiProperty()
11+
@IsString()
12+
@IsNotEmpty()
13+
url: string;
14+
15+
@ApiPropertyOptional()
16+
@IsOptional()
17+
@IsString()
18+
type?: string;
19+
20+
@ApiPropertyOptional()
21+
@IsOptional()
22+
@IsNumber()
23+
size?: number;
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { IsEnum, IsString, IsNotEmpty, IsOptional, IsDateString, IsNumber } from 'class-validator';
2+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
3+
import { MaintenanceType } from '../maintenance.entity';
4+
5+
export class CreateMaintenanceDto {
6+
@ApiProperty({ enum: MaintenanceType })
7+
@IsEnum(MaintenanceType)
8+
type: MaintenanceType;
9+
10+
@ApiProperty()
11+
@IsString()
12+
@IsNotEmpty()
13+
description: string;
14+
15+
@ApiProperty()
16+
@IsDateString()
17+
scheduledDate: string;
18+
19+
@ApiPropertyOptional()
20+
@IsOptional()
21+
@IsString()
22+
notes?: string;
23+
24+
@ApiPropertyOptional()
25+
@IsOptional()
26+
@IsNumber()
27+
cost?: number;
28+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { IsString, IsNotEmpty } from 'class-validator';
2+
import { ApiProperty } from '@nestjs/swagger';
3+
4+
export class CreateNoteDto {
5+
@ApiProperty()
6+
@IsString()
7+
@IsNotEmpty()
8+
content: string;
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2+
import { IsUUID, IsOptional, IsString, MaxLength } from 'class-validator';
3+
4+
export class TransferAssetDto {
5+
@ApiProperty({ example: 'uuid-of-department' })
6+
@IsUUID()
7+
departmentId: string;
8+
9+
@ApiPropertyOptional({ example: 'uuid-of-user' })
10+
@IsUUID()
11+
@IsOptional()
12+
assignedToId?: string;
13+
14+
@ApiPropertyOptional({ example: 'Floor 3, Room 301' })
15+
@IsString()
16+
@IsOptional()
17+
@MaxLength(255)
18+
location?: string;
19+
20+
@ApiPropertyOptional()
21+
@IsString()
22+
@IsOptional()
23+
@MaxLength(1000)
24+
notes?: string;
25+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { PartialType } from '@nestjs/mapped-types';
2+
import { CreateAssetDto } from './create-asset.dto';
3+
4+
export class UpdateAssetDto extends PartialType(CreateAssetDto) {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { IsEnum, IsOptional, IsDateString, IsNumber, IsString } from 'class-validator';
2+
import { ApiPropertyOptional } from '@nestjs/swagger';
3+
import { MaintenanceStatus } from '../maintenance.entity';
4+
5+
export class UpdateMaintenanceDto {
6+
@ApiPropertyOptional({ enum: MaintenanceStatus })
7+
@IsOptional()
8+
@IsEnum(MaintenanceStatus)
9+
status?: MaintenanceStatus;
10+
11+
@ApiPropertyOptional()
12+
@IsOptional()
13+
@IsDateString()
14+
completedDate?: string;
15+
16+
@ApiPropertyOptional()
17+
@IsOptional()
18+
@IsNumber()
19+
cost?: number;
20+
21+
@ApiPropertyOptional()
22+
@IsOptional()
23+
@IsString()
24+
notes?: string;
25+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsEnum } from 'class-validator';
3+
import { AssetStatus } from '../enums';
4+
5+
export class UpdateStatusDto {
6+
@ApiProperty({ enum: AssetStatus })
7+
@IsEnum(AssetStatus)
8+
status: AssetStatus;
9+
}

0 commit comments

Comments
 (0)