1 | import * as bcrypt from "bcrypt-nodejs";
|
2 | import * as crypto from "crypto";
|
3 | import * as mongoose from "mongoose";
|
4 | import { ObjectId } from "mongodb";
|
5 | import { Schema } from "mongoose";
|
6 |
|
7 | const dataSchema = new mongoose.Schema({
|
8 | "Time": {
|
9 | type: Number,
|
10 | index: "2d"
|
11 | },
|
12 | "TimeId": {
|
13 | type: Number
|
14 | },
|
15 | "Endpoint": {
|
16 | type: String,
|
17 | required: true
|
18 | },
|
19 | "Source": {
|
20 | type: Schema.Types.ObjectId,
|
21 | ref: "Source"
|
22 | },
|
23 | "Data": Object,
|
24 | "Events": {
|
25 | default: [],
|
26 | "type": [
|
27 | {
|
28 | "Type": {
|
29 | type: String, required: true, enum: {
|
30 | values: ["threshold", "error"],
|
31 | message: "enum validator failed for path `{PATH}` with value `{VALUE}`"
|
32 | }
|
33 | },
|
34 | "Info": {}
|
35 | }
|
36 | ]
|
37 | }
|
38 | }, {
|
39 | timestamps: true,
|
40 | });
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | dataSchema.pre("save", function save(next) {
|
46 | const data = this;
|
47 | next();
|
48 | });
|
49 |
|
50 | const Data = mongoose.model("Data", dataSchema);
|
51 |
|
52 | export { Data };
|