UNPKG

1.04 kBPlain TextView Raw
1import * as bcrypt from "bcrypt-nodejs";
2import * as crypto from "crypto";
3import * as mongoose from "mongoose";
4import { ObjectId } from "mongodb";
5import { Schema } from "mongoose";
6
7const 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 * pre save dat middleware.
44 */
45dataSchema.pre("save", function save(next) {
46 const data = this;
47 next();
48});
49
50const Data = mongoose.model("Data", dataSchema);
51
52export { Data };