sowell-models 1.0.0
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/.editorconfig +15 -0
- package/.github/workflows/publish.yml +24 -0
- package/.github/workflows/remove-stale-branches.yml +19 -0
- package/.prettierrc +6 -0
- package/LICENSE +201 -0
- package/README.md +20 -0
- package/eslint.config.mjs +43 -0
- package/package.json +47 -0
- package/src/main.ts +26 -0
- package/src/models/Agency/index.ts +48 -0
- package/src/models/ApplicationRecord/index.ts +10 -0
- package/src/models/AreaItem/index.ts +80 -0
- package/src/models/Assignation/index.ts +21 -0
- package/src/models/Author/index.ts +16 -0
- package/src/models/Checklist/index.ts +62 -0
- package/src/models/Checkpoint/index.ts +57 -0
- package/src/models/Company/index.ts +26 -0
- package/src/models/Export/index.ts +27 -0
- package/src/models/Family/index.ts +41 -0
- package/src/models/IssueReport/index.ts +169 -0
- package/src/models/Location/index.ts +23 -0
- package/src/models/Origin/index.ts +44 -0
- package/src/models/Place/index.ts +75 -0
- package/src/models/Provider/index.ts +44 -0
- package/src/models/Reason/index.ts +41 -0
- package/src/models/Residence/index.ts +50 -0
- package/src/models/Sector/index.ts +56 -0
- package/src/models/Spot/index.ts +49 -0
- package/src/models/UnseenIssue/index.ts +17 -0
- package/src/models/User/index.ts +62 -0
- package/src/models/VisitProp/index.ts +38 -0
- package/src/models/VisitReport/index.ts +127 -0
- package/src/models/VisitSchedule/index.ts +58 -0
- package/src/models/category/index.ts +54 -0
- package/src/models/interfaces.ts +8 -0
- package/src/models/types.ts +10 -0
- package/src/utils/arrayDiffBy.ts +14 -0
- package/tsconfig.json +13 -0
- package/tsconfig.release.json +9 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Model, Attr, BelongsTo, HasMany } from "spraypaint"
|
|
2
|
+
import { IModel, PouchCollection, PouchORM } from "pouchorm"
|
|
3
|
+
import { orderBy } from "lodash"
|
|
4
|
+
|
|
5
|
+
import { ICategory, SPCategoryItem } from "../category"
|
|
6
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
7
|
+
import { IChecklist, SPChecklistItem } from "../Checklist"
|
|
8
|
+
import { CollectionFindOptions, IClearable } from "../interfaces"
|
|
9
|
+
import { IVisitProp, SPVisitPropItem } from "../VisitProp"
|
|
10
|
+
import { ILocation, SPLocationItem } from "../Location"
|
|
11
|
+
|
|
12
|
+
export interface ICheckpoint extends IModel {
|
|
13
|
+
_id?: string
|
|
14
|
+
question?: string
|
|
15
|
+
description?: string
|
|
16
|
+
checklist?: IChecklist
|
|
17
|
+
categoryId?: number
|
|
18
|
+
category?: number | ICategory
|
|
19
|
+
visitProps?: IVisitProp[]
|
|
20
|
+
locationId?: number
|
|
21
|
+
location?: ILocation
|
|
22
|
+
coefficient?: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class CheckpointCollection
|
|
26
|
+
extends PouchCollection<ICheckpoint>
|
|
27
|
+
implements IClearable {
|
|
28
|
+
async beforeInit(): Promise<void> {
|
|
29
|
+
// NOTE: none
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async clear(): Promise<void> {
|
|
33
|
+
await PouchORM.clearDatabase("checkpoints")
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async find(
|
|
37
|
+
selector?: Record<string, any> | Partial<ICheckpoint> | undefined,
|
|
38
|
+
opts?: CollectionFindOptions
|
|
39
|
+
) {
|
|
40
|
+
const result = await super.find(selector, opts)
|
|
41
|
+
return orderBy(result, ["question"], ["asc"])
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Model()
|
|
46
|
+
export class SPCheckpointItem extends ApplicationRecord implements ICheckpoint {
|
|
47
|
+
static jsonapiType = "checkpoints"
|
|
48
|
+
@Attr() question!: string
|
|
49
|
+
@Attr() description!: string
|
|
50
|
+
@Attr() categoryId!: number
|
|
51
|
+
@Attr() locationId!: number
|
|
52
|
+
@Attr() coefficient!: number
|
|
53
|
+
@BelongsTo() category!: SPCategoryItem
|
|
54
|
+
@BelongsTo() checklist!: SPChecklistItem
|
|
55
|
+
@BelongsTo() location?: SPLocationItem | undefined
|
|
56
|
+
@HasMany() visitProps?: SPVisitPropItem[] | undefined
|
|
57
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Model, Attr, HasMany } from "spraypaint"
|
|
2
|
+
import { IModel } from "pouchorm"
|
|
3
|
+
|
|
4
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
5
|
+
import { SPAreaItem } from "../AreaItem"
|
|
6
|
+
import { SPAgencyItem } from "../Agency"
|
|
7
|
+
import { SPResidenceItem } from "../Residence"
|
|
8
|
+
import { SPPlaceItem } from "../Place"
|
|
9
|
+
|
|
10
|
+
export interface ICompany extends IModel {
|
|
11
|
+
id?: string
|
|
12
|
+
_id?: string
|
|
13
|
+
name?: string
|
|
14
|
+
config?: string[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Model()
|
|
18
|
+
export class SPCompany extends ApplicationRecord implements ICompany {
|
|
19
|
+
static jsonapiType = "companies"
|
|
20
|
+
@Attr() name!: string
|
|
21
|
+
@Attr() config!: string[]
|
|
22
|
+
@HasMany("areas") spAreaItems!: SPAreaItem[]
|
|
23
|
+
@HasMany("agencies") spAgencyItems!: SPAgencyItem[]
|
|
24
|
+
@HasMany("residences") spResidenceItems!: SPResidenceItem[]
|
|
25
|
+
@HasMany("places") spPlaceItems!: SPPlaceItem[]
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Model, Attr } from "spraypaint"
|
|
2
|
+
|
|
3
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
4
|
+
|
|
5
|
+
export enum ExportStatus {
|
|
6
|
+
ONGOING = "ongoing",
|
|
7
|
+
PENDING = "pending",
|
|
8
|
+
DONE = "done",
|
|
9
|
+
FAILED = "failed"
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IExport {
|
|
13
|
+
id?: string
|
|
14
|
+
name?: string
|
|
15
|
+
status?: ExportStatus
|
|
16
|
+
params?: string
|
|
17
|
+
url?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Model()
|
|
21
|
+
export class SPExport extends ApplicationRecord implements IExport {
|
|
22
|
+
static jsonapiType = "exports"
|
|
23
|
+
@Attr() name!: string
|
|
24
|
+
@Attr() status!: ExportStatus
|
|
25
|
+
@Attr() url!: string
|
|
26
|
+
@Attr() params!: string
|
|
27
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Model, Attr } from "spraypaint"
|
|
2
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
3
|
+
import { PouchCollection, PouchORM } from "pouchorm"
|
|
4
|
+
import { CollectionFindOptions, IClearable } from "../interfaces"
|
|
5
|
+
import { orderBy } from "lodash"
|
|
6
|
+
|
|
7
|
+
export interface IFamily {
|
|
8
|
+
_id?: string
|
|
9
|
+
name?: string
|
|
10
|
+
iconUrl?: string
|
|
11
|
+
}
|
|
12
|
+
@Model()
|
|
13
|
+
export class SPFamily extends ApplicationRecord implements IFamily {
|
|
14
|
+
static jsonapiType = "families"
|
|
15
|
+
@Attr() name!: string
|
|
16
|
+
@Attr() iconUrl!: string
|
|
17
|
+
get _id(): string | undefined {
|
|
18
|
+
return this.id
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class FamilyCollection
|
|
23
|
+
extends PouchCollection<IFamily>
|
|
24
|
+
implements IClearable
|
|
25
|
+
{
|
|
26
|
+
async beforeInit(): Promise<void> {
|
|
27
|
+
// NOTE: none
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async clear(): Promise<void> {
|
|
31
|
+
await PouchORM.clearDatabase("places")
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async find(
|
|
35
|
+
selector?: Record<string, any> | Partial<IFamily> | undefined,
|
|
36
|
+
opts?: CollectionFindOptions
|
|
37
|
+
) {
|
|
38
|
+
const result = await super.find(selector, opts)
|
|
39
|
+
return orderBy(result, ["name"], ["asc"])
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Model, Attr, BelongsTo, HasMany } from "spraypaint"
|
|
2
|
+
import { IModel, PouchCollection, PouchORM } from "pouchorm"
|
|
3
|
+
import { orderBy } from "lodash"
|
|
4
|
+
import * as yup from "yup"
|
|
5
|
+
|
|
6
|
+
import { ICompany, SPCompany } from "../Company"
|
|
7
|
+
import { ICategory, SPCategoryItem } from "../category"
|
|
8
|
+
import { IPlace, SPPlaceItem } from "../Place"
|
|
9
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
10
|
+
import { IUser, SPUserItem } from "../User"
|
|
11
|
+
import { ICheckpoint, SPCheckpointItem } from "../Checkpoint"
|
|
12
|
+
import { SPVisitReport } from "../VisitReport"
|
|
13
|
+
import { IResidence } from "../Residence"
|
|
14
|
+
import { IArea } from "../AreaItem"
|
|
15
|
+
import { CollectionFindOptions, IClearable } from "../interfaces"
|
|
16
|
+
import { ISpot, SPSpotItem } from "./../Spot"
|
|
17
|
+
import arrayDiffBy from "../types"
|
|
18
|
+
import { IReason, SPReasonItem } from "../Reason"
|
|
19
|
+
import { IOrigin, SPOriginItem } from "../Origin"
|
|
20
|
+
import { SPUnseenIssue } from "../UnseenIssue"
|
|
21
|
+
export interface IssueReportPayload {
|
|
22
|
+
category?: string
|
|
23
|
+
agency?: string
|
|
24
|
+
residence?: string
|
|
25
|
+
place?: string
|
|
26
|
+
checkpoint?: string
|
|
27
|
+
description: string
|
|
28
|
+
priority: number
|
|
29
|
+
visitReport?: string
|
|
30
|
+
imgs?: File[]
|
|
31
|
+
spot?: string
|
|
32
|
+
areaNature?: "housing" | "other_spots" | "common_areas" | "zone"
|
|
33
|
+
isTenantRequest?: boolean
|
|
34
|
+
reason?: string
|
|
35
|
+
origin?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type Tab = "mySector" | "others"
|
|
39
|
+
export interface TalkPayload {
|
|
40
|
+
id: string
|
|
41
|
+
issueReportId: string
|
|
42
|
+
message: string
|
|
43
|
+
tab: Tab
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ITalk {
|
|
47
|
+
id: string
|
|
48
|
+
author: {
|
|
49
|
+
id: string
|
|
50
|
+
name: string
|
|
51
|
+
}
|
|
52
|
+
message: string
|
|
53
|
+
files: string[]
|
|
54
|
+
created_at?: Date
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface IIssueReport extends IModel {
|
|
58
|
+
_id?: string
|
|
59
|
+
remoteId?: string
|
|
60
|
+
priority: string
|
|
61
|
+
message: string
|
|
62
|
+
status: string
|
|
63
|
+
checkpointId?: number
|
|
64
|
+
createdAt?: Date
|
|
65
|
+
updatedAt?: Date
|
|
66
|
+
place?: IPlace
|
|
67
|
+
category?: ICategory
|
|
68
|
+
checkpoint?: ICheckpoint
|
|
69
|
+
author?: IUser
|
|
70
|
+
company?: ICompany
|
|
71
|
+
residence?: IResidence
|
|
72
|
+
area?: IArea
|
|
73
|
+
talks?: ITalk[]
|
|
74
|
+
spot?: ISpot | ISpot[]
|
|
75
|
+
imgs?: string[]
|
|
76
|
+
isTenantRequest?:boolean
|
|
77
|
+
reason?: IReason
|
|
78
|
+
origin?: IOrigin
|
|
79
|
+
seen?: boolean
|
|
80
|
+
validate?: () => string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class IssueCollection
|
|
84
|
+
extends PouchCollection<IIssueReport>
|
|
85
|
+
implements IClearable {
|
|
86
|
+
async beforeInit(): Promise<void> {
|
|
87
|
+
await this.addIndex(["_id", "remoteId"])
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async clear(): Promise<void> {
|
|
91
|
+
await PouchORM.clearDatabase("issueReports")
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async find(
|
|
95
|
+
selector?: Record<string, any> | Partial<IIssueReport> | undefined,
|
|
96
|
+
opts?: CollectionFindOptions
|
|
97
|
+
) {
|
|
98
|
+
const result = await super.find(selector, opts)
|
|
99
|
+
return orderBy(result, ["name"], ["asc"])
|
|
100
|
+
}
|
|
101
|
+
async bulkUpsertIfNotExists(items: IIssueReport[]): Promise<IIssueReport[]> {
|
|
102
|
+
const existingItems = await super.find({})
|
|
103
|
+
const diff = arrayDiffBy(existingItems, items, "remoteId")
|
|
104
|
+
const upsertedIssueReport = await super.bulkUpsert(diff.missingLeft)
|
|
105
|
+
return upsertedIssueReport
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Model()
|
|
110
|
+
export class SPIssueReportItem
|
|
111
|
+
extends ApplicationRecord
|
|
112
|
+
implements Partial<IIssueReport> {
|
|
113
|
+
static jsonapiType = "issue_reports"
|
|
114
|
+
@Attr() isTenantRequest!: boolean
|
|
115
|
+
@Attr() message!: string
|
|
116
|
+
@Attr() talks!: ITalk[]
|
|
117
|
+
@Attr() imgs!: string[]
|
|
118
|
+
@Attr() priority!: string
|
|
119
|
+
@Attr() status!: string
|
|
120
|
+
@Attr() checkpointId!: number
|
|
121
|
+
@Attr({ persist: false }) createdAt!: Date
|
|
122
|
+
@Attr({ persist: false }) updatedAt!: Date
|
|
123
|
+
@Attr() pendingIimestamp!: Date
|
|
124
|
+
@Attr() ongoingTimestamp!: Date
|
|
125
|
+
@Attr() doneTimestamp!: Date
|
|
126
|
+
@Attr() canceledTimestamp!: Date
|
|
127
|
+
@Attr() rejectedTimestamp!: Date
|
|
128
|
+
@Attr() seen!: boolean
|
|
129
|
+
@BelongsTo() author!: SPUserItem
|
|
130
|
+
@BelongsTo() category!: SPCategoryItem
|
|
131
|
+
@BelongsTo() residence!: IResidence
|
|
132
|
+
@BelongsTo() place!: SPPlaceItem
|
|
133
|
+
@BelongsTo() spot!: SPSpotItem
|
|
134
|
+
@BelongsTo() company!: SPCompany
|
|
135
|
+
@BelongsTo() visitReport!: SPVisitReport
|
|
136
|
+
@BelongsTo() checkpoint!: SPCheckpointItem
|
|
137
|
+
@BelongsTo() reason!: SPReasonItem
|
|
138
|
+
@BelongsTo() origin?: SPOriginItem | undefined
|
|
139
|
+
@HasMany() unseenIssues!: SPUnseenIssue[]
|
|
140
|
+
|
|
141
|
+
static async validate(payload: IssueReportPayload) {
|
|
142
|
+
const schema = yup
|
|
143
|
+
.object()
|
|
144
|
+
.required()
|
|
145
|
+
.shape({
|
|
146
|
+
category: yup.string(),
|
|
147
|
+
agency: yup.string(),
|
|
148
|
+
residence: yup.string().nullable().notRequired(),
|
|
149
|
+
place: yup.string().nullable().notRequired(),
|
|
150
|
+
spot: yup.string().nullable().notRequired(),
|
|
151
|
+
checkpoint: yup.string(),
|
|
152
|
+
description: yup.string().required(),
|
|
153
|
+
priority: yup.number().required(),
|
|
154
|
+
visitReport: yup.string(),
|
|
155
|
+
isTenantRequest: yup.boolean()
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
const isValid = await schema.isValid(payload)
|
|
159
|
+
|
|
160
|
+
if (!isValid) {
|
|
161
|
+
try {
|
|
162
|
+
await schema.validate(payload)
|
|
163
|
+
} catch (error: any) {
|
|
164
|
+
return error.message
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return "VALID"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Attr, BelongsTo, HasMany, Model } from "spraypaint"
|
|
2
|
+
import { IModel } from "pouchorm"
|
|
3
|
+
|
|
4
|
+
import { IAreaType, SPAreaType } from "../AreaItem"
|
|
5
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
6
|
+
import { ICheckpoint, SPCheckpointItem } from "../Checkpoint"
|
|
7
|
+
|
|
8
|
+
export interface ILocation extends IModel {
|
|
9
|
+
_id?: string
|
|
10
|
+
name?: string
|
|
11
|
+
areaType?: IAreaType
|
|
12
|
+
areaTypeId?: number
|
|
13
|
+
checkpoints?: ICheckpoint[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Model()
|
|
17
|
+
export class SPLocationItem extends ApplicationRecord implements ILocation {
|
|
18
|
+
static jsonapiType = "locations"
|
|
19
|
+
@Attr() name!: string
|
|
20
|
+
@Attr() areaTypeId!: number
|
|
21
|
+
@BelongsTo() areaType!: SPAreaType
|
|
22
|
+
@HasMany() checkpoints?: SPCheckpointItem[] | undefined
|
|
23
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Model, Attr, HasMany } from "spraypaint"
|
|
2
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
3
|
+
import { IModel, PouchCollection, PouchORM } from "pouchorm"
|
|
4
|
+
import { IIssueReport, SPIssueReportItem } from "../IssueReport"
|
|
5
|
+
import { CollectionFindOptions, IClearable } from "../interfaces"
|
|
6
|
+
import { orderBy } from "lodash"
|
|
7
|
+
|
|
8
|
+
export interface IOrigin extends IModel {
|
|
9
|
+
_id?: string
|
|
10
|
+
name?: string
|
|
11
|
+
iconUrl?: string
|
|
12
|
+
issueReports?: IIssueReport[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class OriginCollection
|
|
16
|
+
extends PouchCollection<IOrigin>
|
|
17
|
+
implements IClearable {
|
|
18
|
+
async beforeInit(): Promise<void> {
|
|
19
|
+
// NOTE: none
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async clear(): Promise<void> {
|
|
23
|
+
await PouchORM.clearDatabase("origins")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async find(
|
|
27
|
+
selector?: Record<string, any> | Partial<IOrigin> | undefined,
|
|
28
|
+
opts?: CollectionFindOptions
|
|
29
|
+
) {
|
|
30
|
+
const result = await super.find(selector, opts)
|
|
31
|
+
return orderBy(result, ["name"], ["asc"])
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Model()
|
|
36
|
+
export class SPOriginItem extends ApplicationRecord implements IOrigin {
|
|
37
|
+
static jsonapiType = "origins"
|
|
38
|
+
@Attr() name!: string
|
|
39
|
+
@Attr() iconUrl!: string
|
|
40
|
+
@HasMany() issueReports!: SPIssueReportItem[]
|
|
41
|
+
get _id(): string | undefined {
|
|
42
|
+
return this.id
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Model, Attr, BelongsTo, HasMany } from "spraypaint"
|
|
2
|
+
import { IModel, PouchCollection, PouchORM } from "pouchorm"
|
|
3
|
+
import { orderBy } from "lodash"
|
|
4
|
+
|
|
5
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
6
|
+
import { ICompany, SPCompany } from "../Company"
|
|
7
|
+
import { IResidence, SPResidenceItem } from "../Residence"
|
|
8
|
+
import { IVisitSchedule, SPVisitSchedule } from "../VisitSchedule"
|
|
9
|
+
import { CollectionFindOptions, IClearable } from "../interfaces"
|
|
10
|
+
import { ISpot, SPSpotItem } from "../Spot"
|
|
11
|
+
|
|
12
|
+
export interface IPlace extends IModel {
|
|
13
|
+
_id?: string
|
|
14
|
+
name: string
|
|
15
|
+
zip?: string
|
|
16
|
+
city?: string
|
|
17
|
+
country?: string
|
|
18
|
+
street_number?: string
|
|
19
|
+
street_name?: string
|
|
20
|
+
sectorIds?: string[]
|
|
21
|
+
residenceId?: string
|
|
22
|
+
agencyId?: string
|
|
23
|
+
visitScheduleIds?: string[]
|
|
24
|
+
updatedAt?: Date
|
|
25
|
+
hasScheduledVisit?: boolean
|
|
26
|
+
residence?: IResidence
|
|
27
|
+
company?: ICompany
|
|
28
|
+
spots?: ISpot[]
|
|
29
|
+
visitSchedules?: IVisitSchedule[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class PlaceCollection
|
|
33
|
+
extends PouchCollection<IPlace>
|
|
34
|
+
implements IClearable
|
|
35
|
+
{
|
|
36
|
+
async beforeInit(): Promise<void> {
|
|
37
|
+
// NOTE: none
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async clear(): Promise<void> {
|
|
41
|
+
await PouchORM.clearDatabase("places")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async find(
|
|
45
|
+
selector?: Record<string, any> | Partial<IPlace> | undefined,
|
|
46
|
+
opts?: CollectionFindOptions
|
|
47
|
+
) {
|
|
48
|
+
const result = await super.find(selector, opts)
|
|
49
|
+
return orderBy(result, ["name"], ["asc"])
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Model()
|
|
54
|
+
export class SPPlaceItem extends ApplicationRecord implements IPlace {
|
|
55
|
+
constructor(attrs?: Record<string, any>) {
|
|
56
|
+
super(attrs)
|
|
57
|
+
this.sectorIds = attrs?.sectorIds || []
|
|
58
|
+
}
|
|
59
|
+
static jsonapiType = "places"
|
|
60
|
+
@Attr() name!: string
|
|
61
|
+
@Attr() zip!: string
|
|
62
|
+
@Attr() city!: string
|
|
63
|
+
@Attr() country!: string
|
|
64
|
+
@Attr() street_number!: string
|
|
65
|
+
@Attr() street_name!: string
|
|
66
|
+
@Attr() sectorIds!: string[]
|
|
67
|
+
@Attr({ persist: false }) updatedAt!: Date
|
|
68
|
+
@BelongsTo() residence!: SPResidenceItem
|
|
69
|
+
@BelongsTo() company!: SPCompany
|
|
70
|
+
@HasMany() visitSchedules!: SPVisitSchedule[]
|
|
71
|
+
@HasMany() spots!: SPSpotItem[]
|
|
72
|
+
get _id(): string | undefined {
|
|
73
|
+
return this.id
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Model, Attr } from "spraypaint"
|
|
2
|
+
import { orderBy } from "lodash"
|
|
3
|
+
import { PouchCollection, PouchORM } from "pouchorm"
|
|
4
|
+
import { CollectionFindOptions, IClearable } from "../interfaces"
|
|
5
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
6
|
+
|
|
7
|
+
export interface Provider {
|
|
8
|
+
_id?: string
|
|
9
|
+
fname: string
|
|
10
|
+
lname: string
|
|
11
|
+
email?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ProviderCollection
|
|
15
|
+
extends PouchCollection<Provider>
|
|
16
|
+
implements IClearable
|
|
17
|
+
{
|
|
18
|
+
async beforeInit(): Promise<void> {
|
|
19
|
+
// NOTE: none
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async clear(): Promise<void> {
|
|
23
|
+
await PouchORM.clearDatabase("providers")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async find(
|
|
27
|
+
selector?: Record<string, any> | Partial<Provider> | undefined,
|
|
28
|
+
opts?: CollectionFindOptions
|
|
29
|
+
) {
|
|
30
|
+
const result = await super.find(selector, opts)
|
|
31
|
+
return orderBy(result, ["fname"], ["asc"])
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Model()
|
|
36
|
+
export class SPProvider extends ApplicationRecord implements Provider {
|
|
37
|
+
static jsonapiType = "providers"
|
|
38
|
+
@Attr() fname!: string
|
|
39
|
+
@Attr() lname!: string
|
|
40
|
+
@Attr() email!: string
|
|
41
|
+
get _id(): string | undefined {
|
|
42
|
+
return this.id
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Model, Attr, BelongsTo } from "spraypaint"
|
|
2
|
+
import { IModel, PouchCollection, PouchORM } from "pouchorm"
|
|
3
|
+
import { orderBy } from "lodash"
|
|
4
|
+
|
|
5
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
6
|
+
import { CollectionFindOptions, IClearable } from "../interfaces"
|
|
7
|
+
import { SPCategoryItem } from "../category"
|
|
8
|
+
|
|
9
|
+
export interface IReason extends IModel {
|
|
10
|
+
_id?: string
|
|
11
|
+
name: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ReasonCollection
|
|
15
|
+
extends PouchCollection<IReason>
|
|
16
|
+
implements IClearable {
|
|
17
|
+
async beforeInit(): Promise<void> {
|
|
18
|
+
// NOTE: none
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async clear(): Promise<void> {
|
|
22
|
+
await PouchORM.clearDatabase("reasons")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async find(
|
|
26
|
+
selector?: Record<string, any> | Partial<IReason> | undefined,
|
|
27
|
+
opts?: CollectionFindOptions
|
|
28
|
+
) {
|
|
29
|
+
const result = await super.find(selector, opts)
|
|
30
|
+
return orderBy(result, ["name"], ["asc"])
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Model()
|
|
35
|
+
export class SPReasonItem
|
|
36
|
+
extends ApplicationRecord
|
|
37
|
+
implements IReason {
|
|
38
|
+
static jsonapiType = "reasons"
|
|
39
|
+
@Attr() name!: string
|
|
40
|
+
@BelongsTo() category!: SPCategoryItem
|
|
41
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Model, Attr, BelongsTo, HasMany } from "spraypaint"
|
|
2
|
+
import { IModel, PouchCollection, PouchORM } from "pouchorm"
|
|
3
|
+
import { orderBy } from "lodash"
|
|
4
|
+
|
|
5
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
6
|
+
import { IAgency, SPAgencyItem } from "../Agency"
|
|
7
|
+
import { ICompany, SPCompany } from "../Company"
|
|
8
|
+
import { SPPlaceItem, IPlace } from "../Place"
|
|
9
|
+
import { CollectionFindOptions, IClearable } from "../interfaces"
|
|
10
|
+
|
|
11
|
+
export interface IResidence extends IModel {
|
|
12
|
+
_id?: string
|
|
13
|
+
name: string
|
|
14
|
+
agencyId?: string
|
|
15
|
+
agency?: IAgency
|
|
16
|
+
hasScheduledVisit?: boolean
|
|
17
|
+
places?: IPlace[]
|
|
18
|
+
company?: ICompany
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class ResidenceCollection
|
|
22
|
+
extends PouchCollection<IResidence>
|
|
23
|
+
implements IClearable
|
|
24
|
+
{
|
|
25
|
+
async beforeInit(): Promise<void> {
|
|
26
|
+
// NOTE: none
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async clear(): Promise<void> {
|
|
30
|
+
await PouchORM.clearDatabase("residences")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async find(selector?: Record<string, any> | Partial<IResidence> | undefined, opts?: CollectionFindOptions) {
|
|
34
|
+
const result = await super.find(selector, opts)
|
|
35
|
+
return orderBy(result, ["name"], ["asc"])
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Model()
|
|
40
|
+
export class SPResidenceItem extends ApplicationRecord implements IResidence {
|
|
41
|
+
static jsonapiType = "residences"
|
|
42
|
+
@Attr() name!: string
|
|
43
|
+
@Attr() hasScheduledVisit!: boolean
|
|
44
|
+
@BelongsTo() agency!: SPAgencyItem
|
|
45
|
+
@BelongsTo() company!: SPCompany
|
|
46
|
+
@HasMany() places!: SPPlaceItem[]
|
|
47
|
+
get _id(): string | undefined {
|
|
48
|
+
return this.id
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Attr, BelongsTo, HasMany, Model } from "spraypaint"
|
|
2
|
+
import { CollectionFindOptions, IClearable } from "../interfaces"
|
|
3
|
+
import { ICompany, SPCompany } from "../Company"
|
|
4
|
+
import { IModel, PouchCollection, PouchORM } from "pouchorm"
|
|
5
|
+
import { IAssignation, SPAssignation } from "../Assignation"
|
|
6
|
+
|
|
7
|
+
import { ApplicationRecord } from "../ApplicationRecord"
|
|
8
|
+
|
|
9
|
+
export interface ISector extends IModel {
|
|
10
|
+
id?: string
|
|
11
|
+
name: string
|
|
12
|
+
code: string
|
|
13
|
+
updatedAt?: Date
|
|
14
|
+
company?: ICompany
|
|
15
|
+
assignations?: IAssignation[]
|
|
16
|
+
reporterId?: string
|
|
17
|
+
placesCount?: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class SectorCollection
|
|
21
|
+
extends PouchCollection<ISector>
|
|
22
|
+
implements IClearable
|
|
23
|
+
{
|
|
24
|
+
async beforeInit(): Promise<void> {
|
|
25
|
+
// NOTE: clear
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async clear(): Promise<void> {
|
|
29
|
+
await PouchORM.clearDatabase("sectors")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async find(
|
|
33
|
+
selector?: Record<string, any> | Partial<ISector> | undefined,
|
|
34
|
+
opts?: CollectionFindOptions
|
|
35
|
+
) {
|
|
36
|
+
return super.find(selector, opts)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
@Model()
|
|
40
|
+
export class SPSectorItem extends ApplicationRecord implements ISector {
|
|
41
|
+
constructor(attrs?: Record<string, any>) {
|
|
42
|
+
super(attrs)
|
|
43
|
+
this.placesCount = attrs?.placesCount || 0
|
|
44
|
+
}
|
|
45
|
+
static jsonapiType = "sectors"
|
|
46
|
+
@Attr() name!: string
|
|
47
|
+
@Attr() code!: string
|
|
48
|
+
@Attr() reporterId!: string
|
|
49
|
+
@Attr({ persist: false }) placesCount?: number | undefined
|
|
50
|
+
@Attr({ persist: false }) updatedAt!: Date
|
|
51
|
+
@BelongsTo() company!: SPCompany
|
|
52
|
+
@HasMany() assignations!: SPAssignation[]
|
|
53
|
+
get _id(): string | undefined {
|
|
54
|
+
return this.id
|
|
55
|
+
}
|
|
56
|
+
}
|