Skip to content

Commit 0997671

Browse files
committed
WIP tickets schematic
1 parent 30a75e7 commit 0997671

File tree

7 files changed

+94
-15
lines changed

7 files changed

+94
-15
lines changed

service/src/_common/enum/user-type.enum.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export enum UserType {
32
CONSOLE = 0,
43
OPERATOR = 1,

service/src/_common/schemas/parts/idname.part.schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { Document, Types } from 'mongoose'
55
export class IdnamePart extends Document {
66
@Prop({
77
type: Types.ObjectId,
8-
required: [true, 'Identifiant obligatoire'],
8+
required: true,
99
})
1010
public id: Types.ObjectId
1111

1212
@Prop({
1313
type: String,
14-
required: [true, 'Nom obligatoire'],
14+
required: true,
1515
})
1616
public name: string
1717
}

service/src/_common/schemas/parts/user.part.schema.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import { UserTypeList } from '~/_common/enum/user-type.enum'
44

55
@Schema({ _id: false })
66
export class UserPart extends IdnamePart {
7-
87
@Prop({
98
type: Number,
109
enum: UserTypeList,
11-
required: [true, 'Type obligatoire'],
10+
required: true,
1211
})
1312
public type: number
1413
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export enum TicketLifestep {
2+
MERGED = -2,
3+
ARCHIVED = -1,
4+
CLOSED = 0,
5+
OPEN = 1,
6+
}
7+
8+
export const TicketLifestepList: number[] = Object.keys(TicketLifestep)
9+
.filter((k) => typeof TicketLifestep[k as any] === 'number')
10+
.map((k) => parseInt(TicketLifestep[k as any], 10))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export enum TicketType {
2+
INCIDENT = 1,
3+
REQUEST = 2,
4+
}
5+
6+
export const TicketTypeList: number[] = Object.keys(TicketType)
7+
.filter((k) => typeof TicketType[k as any] === 'number')
8+
.map((k) => parseInt(TicketType[k as any], 10))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2+
import { IdnamePart } from '~/_common/schemas/parts/idname.part.schema'
3+
4+
@Schema({ _id: false })
5+
export class SlaPart extends IdnamePart {
6+
@Prop({
7+
type: Date,
8+
required: true,
9+
default: new Date(),
10+
})
11+
public dueAt: Date
12+
13+
@Prop({
14+
type: Boolean,
15+
required: true,
16+
default: false,
17+
})
18+
public manual: boolean
19+
}
20+
21+
export const SlaPartSchema = SchemaFactory.createForClass(SlaPart)

service/src/tickets/ticket/_schemas/ticket.schema.ts

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
22
import { AbstractSchema } from '~/_common/abstracts/schemas/abstract.schema'
33
import { AutoIncrementPlugin } from '~/_common/plugins/mongoose/auto-increment.plugin'
44
import { AutoIncrementPluginOptions } from '~/_common/plugins/mongoose/auto-increment.interface'
5-
import { IdnamePart } from '~/_common/schemas/parts/idname.part.schema'
5+
import { IdnamePart, IdnamePartSchema } from '~/_common/schemas/parts/idname.part.schema'
6+
import { TicketTypeList } from '~/tickets/ticket/_enum/ticket-type.enum'
7+
import { TicketLifestepList } from '~/tickets/ticket/_enum/ticket-lifestep.enum'
8+
import { Types } from 'mongoose'
9+
import { SlaPart, SlaPartSchema } from '~/tickets/ticket/_schemas/parts/sla.part.schema'
610

711
@Schema({
812
collection: 'tickets',
@@ -23,28 +27,66 @@ export class Ticket extends AbstractSchema {
2327
public subject: string
2428

2529
@Prop({
26-
type: IdnamePart,
27-
required: [true, 'Le status du ticket doit être spécifié'],
30+
type: Number,
31+
enum: TicketTypeList,
32+
required: true,
33+
})
34+
public type: number
35+
36+
public envelope
37+
38+
@Prop({
39+
type: Number,
40+
enum: TicketLifestepList,
41+
required: true,
42+
})
43+
public lifestep: number
44+
45+
@Prop({ type: Types.ObjectId })
46+
public parent?: Types.ObjectId
47+
48+
@Prop({
49+
type: IdnamePartSchema,
50+
required: true,
2851
})
2952
public state: IdnamePart
3053

3154
@Prop({
32-
type: IdnamePart,
33-
required: [true, 'Le projet du ticket doit être spécifié'],
55+
type: IdnamePartSchema,
56+
required: true,
3457
})
3558
public project: IdnamePart
3659

3760
@Prop({
38-
type: IdnamePart,
39-
required: [true, 'La priorité du ticket doit être spécifié'],
61+
type: IdnamePartSchema,
62+
required: true,
4063
})
4164
public priority: IdnamePart
4265

4366
@Prop({
44-
type: IdnamePart,
45-
required: [true, 'L\'impact du ticket doit être spécifié'],
67+
type: IdnamePartSchema,
68+
required: true,
4669
})
4770
public impact: IdnamePart
71+
72+
@Prop({
73+
type: SlaPartSchema,
74+
required: true,
75+
})
76+
public sla: SlaPart
77+
78+
@Prop({
79+
type: Number,
80+
required: true,
81+
default: 0,
82+
})
83+
public totalTime: number
84+
85+
@Prop({
86+
type: [String],
87+
default: [],
88+
})
89+
public readFlags: string[]
4890
}
4991

5092
export const TicketSchema = SchemaFactory.createForClass(Ticket)
@@ -55,7 +97,7 @@ export const TicketSchema = SchemaFactory.createForClass(Ticket)
5597
})
5698
.pre('save', function(next) {
5799
if (this.isNew) {
58-
this.sequence = 'LT' + this.sequence.padStart(6, '0')
100+
this.sequence = 'LT' + this.sequence.padStart(6, '0') //TODO: get prefix from config
59101
}
60102
next()
61103
})

0 commit comments

Comments
 (0)