codebase-models 2.1.22 → 2.1.23
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.
|
@@ -38,6 +38,8 @@ const CronConfigSchema = new mongoose_1.Schema({
|
|
|
38
38
|
iid: {
|
|
39
39
|
type: String,
|
|
40
40
|
unique: true,
|
|
41
|
+
sparse: true, // ✅ avoids null duplication
|
|
42
|
+
default: () => (0, constant_1.generateRandomIID)(), // ✅ auto-generate always
|
|
41
43
|
},
|
|
42
44
|
organizationId: {
|
|
43
45
|
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
@@ -86,7 +88,7 @@ const CronConfigSchema = new mongoose_1.Schema({
|
|
|
86
88
|
required: true,
|
|
87
89
|
},
|
|
88
90
|
}, {
|
|
89
|
-
timestamps: true
|
|
91
|
+
timestamps: true,
|
|
90
92
|
});
|
|
91
93
|
CronConfigSchema.pre("save", function (next) {
|
|
92
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -98,5 +100,7 @@ CronConfigSchema.pre("save", function (next) {
|
|
|
98
100
|
});
|
|
99
101
|
CronConfigSchema.index({ test: 1 });
|
|
100
102
|
CronConfigSchema.index({ client: 1 });
|
|
101
|
-
|
|
103
|
+
CronConfigSchema.index({ iid: 1 }, { unique: true, sparse: true });
|
|
104
|
+
const CronConfig = mongoose_1.default.models.cronConfig ||
|
|
105
|
+
(0, mongoose_1.model)("cronConfig", CronConfigSchema);
|
|
102
106
|
exports.default = CronConfig;
|
package/package.json
CHANGED
package/src/models/CronConfig.ts
CHANGED
|
@@ -2,83 +2,91 @@ import mongoose, { Document, Schema, model } from "mongoose";
|
|
|
2
2
|
import { generateRandomIID } from "../constant";
|
|
3
3
|
|
|
4
4
|
export interface ICronConfig extends Document {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
iid: string;
|
|
6
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
7
|
+
jobName: string;
|
|
8
|
+
description: string;
|
|
9
|
+
client: mongoose.Schema.Types.ObjectId;
|
|
10
|
+
test: mongoose.Schema.Types.ObjectId;
|
|
11
|
+
active: boolean;
|
|
12
|
+
lastRun: Date;
|
|
13
|
+
nextRun: Date;
|
|
14
|
+
schedule: string;
|
|
15
|
+
metadata: mongoose.Schema.Types.Mixed;
|
|
16
|
+
createdBy: mongoose.Schema.Types.ObjectId;
|
|
17
17
|
}
|
|
18
|
-
const CronConfigSchema = new Schema<ICronConfig>(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const CronConfigSchema = new Schema<ICronConfig>(
|
|
19
|
+
{
|
|
20
|
+
iid: {
|
|
21
|
+
type: String,
|
|
22
|
+
unique: true,
|
|
23
|
+
sparse: true, // ✅ avoids null duplication
|
|
24
|
+
default: () => generateRandomIID(), // ✅ auto-generate always
|
|
25
|
+
},
|
|
26
|
+
organizationId: {
|
|
27
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
28
|
+
ref: "organization",
|
|
29
|
+
default: null,
|
|
30
|
+
},
|
|
31
|
+
jobName: {
|
|
32
|
+
type: String,
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
description: {
|
|
36
|
+
type: String,
|
|
37
|
+
},
|
|
38
|
+
client: {
|
|
39
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
40
|
+
ref: "client",
|
|
41
|
+
},
|
|
42
|
+
test: {
|
|
43
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
44
|
+
ref: "test",
|
|
45
|
+
},
|
|
46
|
+
active: {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
default: true,
|
|
49
|
+
},
|
|
50
|
+
lastRun: {
|
|
51
|
+
type: Date,
|
|
52
|
+
default: null,
|
|
53
|
+
},
|
|
54
|
+
nextRun: {
|
|
55
|
+
type: Date,
|
|
56
|
+
default: null,
|
|
57
|
+
},
|
|
58
|
+
schedule: {
|
|
59
|
+
type: String,
|
|
60
|
+
required: true,
|
|
61
|
+
},
|
|
62
|
+
metadata: {
|
|
63
|
+
type: mongoose.Schema.Types.Mixed,
|
|
64
|
+
default: null,
|
|
65
|
+
},
|
|
66
|
+
createdBy: {
|
|
67
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
68
|
+
ref: "user",
|
|
69
|
+
default: null,
|
|
70
|
+
required: true,
|
|
71
|
+
},
|
|
22
72
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
jobName: {
|
|
29
|
-
type: String,
|
|
30
|
-
required: true,
|
|
31
|
-
},
|
|
32
|
-
description: {
|
|
33
|
-
type: String,
|
|
34
|
-
},
|
|
35
|
-
client: {
|
|
36
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
37
|
-
ref: "client",
|
|
38
|
-
},
|
|
39
|
-
test: {
|
|
40
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
41
|
-
ref: "test",
|
|
42
|
-
},
|
|
43
|
-
active: {
|
|
44
|
-
type: Boolean,
|
|
45
|
-
default: true,
|
|
46
|
-
},
|
|
47
|
-
lastRun: {
|
|
48
|
-
type: Date,
|
|
49
|
-
default: null,
|
|
50
|
-
},
|
|
51
|
-
nextRun: {
|
|
52
|
-
type: Date,
|
|
53
|
-
default: null,
|
|
54
|
-
},
|
|
55
|
-
schedule: {
|
|
56
|
-
type: String,
|
|
57
|
-
required: true,
|
|
58
|
-
},
|
|
59
|
-
metadata: {
|
|
60
|
-
type: mongoose.Schema.Types.Mixed,
|
|
61
|
-
default: null,
|
|
62
|
-
},
|
|
63
|
-
createdBy: {
|
|
64
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
65
|
-
ref: "user",
|
|
66
|
-
default: null,
|
|
67
|
-
required: true,
|
|
68
|
-
},
|
|
69
|
-
}, {
|
|
70
|
-
timestamps: true
|
|
71
|
-
});
|
|
73
|
+
{
|
|
74
|
+
timestamps: true,
|
|
75
|
+
}
|
|
76
|
+
);
|
|
72
77
|
|
|
73
78
|
CronConfigSchema.pre("save", async function (next) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
if (!this.iid) {
|
|
80
|
+
this.iid = generateRandomIID();
|
|
81
|
+
}
|
|
82
|
+
next();
|
|
83
|
+
});
|
|
79
84
|
|
|
80
85
|
CronConfigSchema.index({ test: 1 });
|
|
81
86
|
CronConfigSchema.index({ client: 1 });
|
|
87
|
+
CronConfigSchema.index({ iid: 1 }, { unique: true, sparse: true });
|
|
82
88
|
|
|
83
|
-
const CronConfig =
|
|
89
|
+
const CronConfig =
|
|
90
|
+
mongoose.models.cronConfig ||
|
|
91
|
+
model<ICronConfig>("cronConfig", CronConfigSchema);
|
|
84
92
|
export default CronConfig;
|