-
Notifications
You must be signed in to change notification settings - Fork 2
/
db.ts
136 lines (126 loc) · 2.65 KB
/
db.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import {FilterQuery, LeanDocument, Query} from 'mongoose';
import {Callback, FuzzyQuery, Search} from 'mongoose-fuzzy-searching';
import {IStore, IStoreRequest, ITransaction, IUser} from '../struct/index.js';
import {isValidEnumValue, isValidEnumValueArray, Modify} from './index.js';
export abstract class MongooseFuzzyClass {
public static fuzzySearch:
| (<T extends MongooseFuzzyClass, QueryHelpers = {}>(
query: Search,
additionalQuery?: FilterQuery<T>,
callback?: Callback<FuzzyQuery<T>, QueryHelpers>,
) => Query<FuzzyQuery<T>[], FuzzyQuery<T>, QueryHelpers>)
| (<T extends MongooseFuzzyClass, QueryHelpers = {}>(
query: Search,
callback?: Callback<FuzzyQuery<T>, QueryHelpers>,
) => Query<FuzzyQuery<T>[], FuzzyQuery<T>, QueryHelpers>);
}
export enum UserRoles {
NONE = 0,
STUDENT = 0b00010,
STAFF = 0b00100,
ADMIN = 0b01000,
BULK_SEND = 0b10000,
ALL = STUDENT | STAFF | ADMIN | BULK_SEND,
}
export type UserRoleTypes = keyof typeof UserRoles;
export const isValidRole = (role: unknown): role is UserRoleTypes =>
isValidEnumValue(UserRoles, role);
export const isValidRoles = (roles: unknown): roles is UserRoleTypes[] =>
isValidEnumValueArray(UserRoles, roles);
export type IUserAPIResponse = Modify<
LeanDocument<IUser>,
{
roles: UserRoleTypes[];
authorized?: boolean;
scopes: string[];
},
'tokens'
>;
export type ITransactionAPIResponse = Modify<
LeanDocument<ITransaction>,
{
_id: string;
/**
* The date of the transaction (ISO format)
*/
date: string;
from: {
/**
* The user's id
*/
id?: string;
/**
* Text to display (for non-user transactions)
*/
text?: string;
/**
* Is from current user
*/
me?: boolean;
};
to: {
/**
* The user's id
*/
id?: string;
/**
* Text to display (for non-user transactions)
*/
text?: string;
/**
* Is to current user
*/
me?: boolean;
};
/**
* Can be managed by current user
*/
canManage: boolean;
}
>;
export type IStoreAPIResponse = Modify<
LeanDocument<IStore>,
{
canManage: boolean;
classIDs?: string[];
classNames?: string[];
users?: {
name: string;
id: string;
}[];
managers?: {
name: string;
id: string;
}[];
owner?: {
name: string;
id: string;
};
}
>;
export enum StoreRequestStatus {
PENDING = 0,
APPROVED = 1,
DENIED = 2,
CANCELLED = 3,
}
export type IStoreRequestAPIResponse = Modify<
LeanDocument<IStoreRequest>,
{
date: string;
store: {
name: string;
id: string;
};
item: {
name: string;
id: string;
};
student: {
name: string;
id: string;
};
status: string;
},
'storeID' | 'itemID' | 'studentID'
>;