sowell-models 1.8.1 → 1.8.3
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/package.json
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import { Model
|
|
2
|
-
import { ICompany } from "../Company"
|
|
1
|
+
import { Model } from "spraypaint"
|
|
3
2
|
import { SPUserItem } from "../User"
|
|
4
|
-
|
|
5
|
-
export interface Author {
|
|
6
|
-
_id?: string
|
|
7
|
-
fname: string
|
|
8
|
-
lname: string
|
|
9
|
-
email?: string
|
|
10
|
-
company?: ICompany
|
|
11
|
-
}
|
|
12
3
|
@Model()
|
|
13
4
|
export class SPAuthor extends SPUserItem {
|
|
14
5
|
static jsonapiType = "authors"
|
|
15
|
-
@Attr() name!: string
|
|
16
6
|
}
|
|
17
7
|
|
|
18
8
|
@Model()
|
|
@@ -55,6 +55,17 @@ export interface ITalk {
|
|
|
55
55
|
files: string[]
|
|
56
56
|
created_at?: Date
|
|
57
57
|
}
|
|
58
|
+
export type ActivityName = "assignation" | "status" | "email" | "erp"
|
|
59
|
+
export interface IActivity extends IModel {
|
|
60
|
+
_id?: string
|
|
61
|
+
name: ActivityName
|
|
62
|
+
createdAt: Date
|
|
63
|
+
metadata?: Record<string, any>
|
|
64
|
+
authorId?: string
|
|
65
|
+
author?: IUser
|
|
66
|
+
issueReportId?: string
|
|
67
|
+
issueReport?: IIssueReport
|
|
68
|
+
}
|
|
58
69
|
|
|
59
70
|
export interface IIssueReport extends IModel {
|
|
60
71
|
_id?: string
|
|
@@ -73,9 +84,10 @@ export interface IIssueReport extends IModel {
|
|
|
73
84
|
residence?: IResidence
|
|
74
85
|
area?: IArea
|
|
75
86
|
talks?: ITalk[]
|
|
87
|
+
activities?: IActivity[]
|
|
76
88
|
spot?: ISpot | ISpot[]
|
|
77
89
|
imgs?: string[]
|
|
78
|
-
isTenantRequest?:boolean
|
|
90
|
+
isTenantRequest?: boolean
|
|
79
91
|
reason?: IReason
|
|
80
92
|
origin?: IOrigin
|
|
81
93
|
assignee?: IUser
|
|
@@ -85,7 +97,8 @@ export interface IIssueReport extends IModel {
|
|
|
85
97
|
|
|
86
98
|
export class IssueCollection
|
|
87
99
|
extends PouchCollection<IIssueReport>
|
|
88
|
-
implements IClearable
|
|
100
|
+
implements IClearable
|
|
101
|
+
{
|
|
89
102
|
async beforeInit(): Promise<void> {
|
|
90
103
|
await this.addIndex(["_id", "remoteId"])
|
|
91
104
|
}
|
|
@@ -96,7 +109,7 @@ export class IssueCollection
|
|
|
96
109
|
|
|
97
110
|
async find(
|
|
98
111
|
selector?: Record<string, any> | Partial<IIssueReport> | undefined,
|
|
99
|
-
opts?: CollectionFindOptions
|
|
112
|
+
opts?: CollectionFindOptions,
|
|
100
113
|
): Promise<IIssueReport[]> {
|
|
101
114
|
const result = await super.find(selector, opts)
|
|
102
115
|
return orderBy(result, ["name"], ["asc"])
|
|
@@ -109,10 +122,20 @@ export class IssueCollection
|
|
|
109
122
|
}
|
|
110
123
|
}
|
|
111
124
|
|
|
125
|
+
@Model()
|
|
126
|
+
export class SPActivity extends ApplicationRecord implements IActivity {
|
|
127
|
+
static jsonapiType = "activities"
|
|
128
|
+
@Attr() name!: ActivityName
|
|
129
|
+
@Attr({ persist: false }) createdAt!: Date
|
|
130
|
+
@Attr() metadata!: Record<string, any>
|
|
131
|
+
@BelongsTo() issueReport!: SPIssueReportItem
|
|
132
|
+
@BelongsTo() author!: SPUserItem
|
|
133
|
+
}
|
|
112
134
|
@Model()
|
|
113
135
|
export class SPIssueReportItem
|
|
114
136
|
extends ApplicationRecord
|
|
115
|
-
implements Partial<IIssueReport>
|
|
137
|
+
implements Partial<IIssueReport>
|
|
138
|
+
{
|
|
116
139
|
static jsonapiType = "issue_reports"
|
|
117
140
|
@Attr() isTenantRequest!: boolean
|
|
118
141
|
@Attr() message!: string
|
|
@@ -141,23 +164,21 @@ export class SPIssueReportItem
|
|
|
141
164
|
@BelongsTo() origin?: SPOriginItem | undefined
|
|
142
165
|
@BelongsTo() assignee?: SPAssignee
|
|
143
166
|
@HasMany() unseenIssues!: SPUnseenIssue[]
|
|
167
|
+
@HasMany() activities!: SPActivity[]
|
|
144
168
|
|
|
145
169
|
static async validate(payload: IssueReportPayload): Promise<string> {
|
|
146
|
-
const schema = yup
|
|
147
|
-
.
|
|
148
|
-
.
|
|
149
|
-
.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
visitReport: yup.string(),
|
|
159
|
-
isTenantRequest: yup.boolean()
|
|
160
|
-
})
|
|
170
|
+
const schema = yup.object().required().shape({
|
|
171
|
+
category: yup.string(),
|
|
172
|
+
agency: yup.string(),
|
|
173
|
+
residence: yup.string().nullable().notRequired(),
|
|
174
|
+
place: yup.string().nullable().notRequired(),
|
|
175
|
+
spot: yup.string().nullable().notRequired(),
|
|
176
|
+
checkpoint: yup.string(),
|
|
177
|
+
description: yup.string().required(),
|
|
178
|
+
priority: yup.number().required(),
|
|
179
|
+
visitReport: yup.string(),
|
|
180
|
+
isTenantRequest: yup.boolean(),
|
|
181
|
+
})
|
|
161
182
|
|
|
162
183
|
const isValid = await schema.isValid(payload)
|
|
163
184
|
|
package/src/models/User/index.ts
CHANGED
|
@@ -44,6 +44,24 @@ export class UserCollection extends PouchCollection<IUser> {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
export class AssigneeCollection extends PouchCollection<IUser> {
|
|
48
|
+
async beforeInit(): Promise<void> {
|
|
49
|
+
await this.addIndex(["id"])
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async clear(): Promise<void> {
|
|
53
|
+
await PouchORM.clearDatabase("assignees")
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async bulkUpsertIfNotExists(items: IUser[]): Promise<IUser[]> {
|
|
57
|
+
const existingItems = await super.find({})
|
|
58
|
+
const diff = arrayDiffBy(existingItems, items, "id")
|
|
59
|
+
const upsertedIssueReport = await super.bulkUpsert(diff.missingLeft)
|
|
60
|
+
return upsertedIssueReport
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
47
65
|
@Model()
|
|
48
66
|
export class SPUserItem extends ApplicationRecord implements IUser {
|
|
49
67
|
static jsonapiType = "users"
|