-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathproposal.schema.ts
184 lines (167 loc) · 3.77 KB
/
proposal.schema.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { ApiProperty } from "@nestjs/swagger";
import { Document } from "mongoose";
import { OwnableClass } from "src/common/schemas/ownable.schema";
import {
MeasurementPeriodClass,
MeasurementPeriodSchema,
} from "./measurement-period.schema";
export type ProposalDocument = ProposalClass & Document;
@Schema({
collection: "Proposal",
toJSON: {
getters: true,
},
timestamps: true,
})
export class ProposalClass extends OwnableClass {
@ApiProperty({
type: String,
required: true,
description:
"Globally unique identifier of a proposal, eg. PID-prefix/internal-proposal-number. PID prefix is auto prepended.",
})
@Prop({
type: String,
unique: true,
required: true,
})
proposalId: string;
@Prop({
type: String,
})
_id: string;
@ApiProperty({
type: String,
required: false,
description: "Email of principal investigator.",
})
@Prop({
type: String,
required: false,
index: true,
})
pi_email?: string;
@ApiProperty({
type: String,
required: false,
description: "First name of principal investigator.",
})
@Prop({
type: String,
required: false,
})
pi_firstname?: string;
@ApiProperty({
type: String,
required: false,
description: "Last name of principal investigator.",
})
@Prop({
type: String,
required: false,
})
pi_lastname?: string;
@ApiProperty({
type: String,
required: true,
description: "Email of main proposer.",
})
@Prop({
type: String,
required: true,
})
email: string;
@ApiProperty({
type: String,
required: false,
description: "First name of main proposer.",
})
@Prop({
type: String,
required: false,
})
firstname?: string;
@ApiProperty({
type: String,
required: false,
description: "Last name of main proposer.",
})
@Prop({
type: String,
required: false,
})
lastname?: string;
@ApiProperty({
type: String,
required: true,
description: "The title of the proposal.",
})
@Prop({
type: String,
required: true,
})
title: string;
@ApiProperty({
type: String,
required: false,
description: "The proposal abstract.",
})
@Prop({
type: String,
required: false,
})
abstract?: string;
@ApiProperty({
type: Date,
required: false,
description: "The date when the data collection starts.",
})
@Prop({
type: Date,
required: false,
})
startTime?: Date;
@ApiProperty({
type: Date,
required: false,
description: "The date when data collection finishes.",
})
@Prop({
type: Date,
required: false,
})
endTime?: Date;
@ApiProperty({
type: MeasurementPeriodClass,
isArray: true,
required: false,
description:
"Embedded information used inside proposals to define which type of experiment has to be pursued, where (at which instrument) and when.",
})
@Prop({
type: [MeasurementPeriodSchema],
required: false,
validate: {
validator: function (measurementPeriodList: MeasurementPeriodClass[]) {
const ids = measurementPeriodList.map(
(measurementPeriod) => measurementPeriod.id,
);
return ids.length === new Set(ids).size;
},
message:
"MeasurementPeriod id must be unique within the MeasurementPeriodList",
},
})
MeasurementPeriodList?: MeasurementPeriodClass[];
@ApiProperty({
type: Object,
required: false,
default: {},
description: "JSON object containing the proposal metadata.",
})
@Prop({ type: Object, required: false, default: {} })
metadata?: Record<string, unknown>;
}
export const ProposalSchema = SchemaFactory.createForClass(ProposalClass);
ProposalSchema.index({ "$**": "text" });