sowell-models 1.1.1 → 1.2.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/package.json +1 -1
- package/src/models/Reason/index.ts +21 -20
package/package.json
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import { Model, Attr, BelongsTo } from
|
|
2
|
-
import { IModel, PouchCollection, PouchORM } from
|
|
3
|
-
import { orderBy } from
|
|
1
|
+
import { Model, Attr, BelongsTo } from 'spraypaint';
|
|
2
|
+
import { IModel, PouchCollection, PouchORM } from 'pouchorm';
|
|
3
|
+
import { orderBy } from 'lodash';
|
|
4
4
|
|
|
5
|
-
import { ApplicationRecord } from
|
|
6
|
-
import { CollectionFindOptions, IClearable } from
|
|
7
|
-
import { SPCategoryItem } from
|
|
5
|
+
import { ApplicationRecord } from '../ApplicationRecord';
|
|
6
|
+
import { CollectionFindOptions, IClearable } from '../interfaces';
|
|
7
|
+
import { SPCategoryItem } from '../category';
|
|
8
8
|
|
|
9
9
|
export interface IReason extends IModel {
|
|
10
|
-
_id?: string
|
|
11
|
-
name: string
|
|
10
|
+
_id?: string;
|
|
11
|
+
name: string;
|
|
12
|
+
iconUrl?: string;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export class ReasonCollection
|
|
15
16
|
extends PouchCollection<IReason>
|
|
16
|
-
implements IClearable
|
|
17
|
+
implements IClearable
|
|
18
|
+
{
|
|
17
19
|
async beforeInit(): Promise<void> {
|
|
18
20
|
// NOTE: none
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
async clear(): Promise<void> {
|
|
22
|
-
await PouchORM.clearDatabase(
|
|
24
|
+
await PouchORM.clearDatabase('reasons');
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
async find(
|
|
26
28
|
selector?: Record<string, any> | Partial<IReason> | undefined,
|
|
27
|
-
opts?: CollectionFindOptions
|
|
28
|
-
) {
|
|
29
|
-
const result = await super.find(selector, opts)
|
|
30
|
-
return orderBy(result, [
|
|
29
|
+
opts?: CollectionFindOptions,
|
|
30
|
+
): Promise<IReason[]> {
|
|
31
|
+
const result = await super.find(selector, opts);
|
|
32
|
+
return orderBy(result, ['name'], ['asc']);
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
@Model()
|
|
35
|
-
export class SPReasonItem
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@
|
|
40
|
-
@BelongsTo() category!: SPCategoryItem
|
|
37
|
+
export class SPReasonItem extends ApplicationRecord implements IReason {
|
|
38
|
+
static jsonapiType = 'reasons';
|
|
39
|
+
@Attr() name!: string;
|
|
40
|
+
@Attr() iconUrl?: string;
|
|
41
|
+
@BelongsTo() category!: SPCategoryItem;
|
|
41
42
|
}
|