Skip to content

Commit bb844fd

Browse files
committed
WIP threads schema
1 parent 74142ca commit bb844fd

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export enum FragmentType {
2+
INLINE = 'inline',
3+
ATTACHMENT = 'attachment',
4+
}
5+
6+
export const FragmentTypeList: number[] = Object.keys(FragmentType)
7+
.filter((k) => typeof FragmentType[k] === 'string')
8+
.map((k) => FragmentType[k])
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2+
import { IdnamePart } from '~/_common/schemas/parts/idname.part.schema'
3+
import { FragmentType, FragmentTypeList } from '~/tickets/thread/_enum/fragment-type.enum'
4+
5+
@Schema({ _id: false })
6+
export class FragmentPart extends IdnamePart {
7+
@Prop({
8+
type: String,
9+
enum: FragmentTypeList,
10+
required: true,
11+
})
12+
public disposition: FragmentType
13+
14+
@Prop({
15+
type: String,
16+
required: true,
17+
})
18+
public type: string
19+
20+
@Prop({
21+
type: String,
22+
required: true,
23+
})
24+
public path: string
25+
26+
@Prop({
27+
type: Object,
28+
})
29+
public metadata: object
30+
}
31+
32+
export const FragmentPartSchema = SchemaFactory.createForClass(FragmentPart)
Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,49 @@
1-
import { Schema, SchemaFactory } from '@nestjs/mongoose'
1+
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
22
import { AbstractSchema } from '~/_common/abstracts/schemas/abstract.schema'
3+
import { Types } from 'mongoose'
4+
import { IdnamePart, IdnamePartSchema } from '~/_common/schemas/parts/idname.part.schema'
5+
import { FragmentPart, FragmentPartSchema } from '~/tickets/thread/_schemas/parts/fragment.part.schema'
36

47
@Schema({
58
collection: 'threads',
69
versionKey: false,
710
})
8-
export class Thread extends AbstractSchema {}
11+
export class Thread extends AbstractSchema {
12+
@Prop({
13+
type: Types.ObjectId,
14+
required: true,
15+
})
16+
public ticketId: Types.ObjectId
17+
18+
@Prop({
19+
type: IdnamePartSchema,
20+
required: true,
21+
})
22+
public sourceRequest: IdnamePart
23+
24+
@Prop({
25+
required: true,
26+
type: String,
27+
})
28+
public message: string
29+
30+
@Prop({
31+
type: Number,
32+
required: true,
33+
default: 0,
34+
})
35+
public timeSpend: number
36+
37+
@Prop({
38+
type: [FragmentPartSchema],
39+
default: [],
40+
})
41+
public fragments: FragmentPart[]
42+
43+
@Prop({
44+
type: Object,
45+
})
46+
public customFields: object
47+
}
948

1049
export const ThreadSchema = SchemaFactory.createForClass(Thread)

0 commit comments

Comments
 (0)