-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.listing.ts
53 lines (46 loc) · 1.13 KB
/
job.listing.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
import mongoose from "mongoose";
interface IJobListing {
id: string;
title: string;
description: string;
location: string;
deadline: Date;
employer: mongoose.Types.ObjectId;
application: Array<mongoose.Types.ObjectId>;
salary: number;
company: string;
}
const defaultDuration = () => Date.now() + 1000 * 60 * 60 * 24 * 7; // a week
const jobListingDefinition = {
title: { type: String, required: true },
description: { type: String, required: true },
location: { type: String },
deadline: {
type: Date,
default: new Date(defaultDuration()),
},
salary: {
type: Number,
required: false,
},
company: {
type: String,
required: true,
},
employer: { type: mongoose.Schema.Types.ObjectId, ref: "Employer" },
applications: [
{ type: mongoose.Schema.Types.ObjectId, ref: "JobApplication" },
],
};
const jobListingSchema = new mongoose.Schema(jobListingDefinition, {
timestamps: true,
});
jobListingSchema.set("toJSON", {
transform: function (doc, ret) {
ret.id = ret._id;
delete ret._id;
delete ret.__v;
},
});
const JobListing = mongoose.model<IJobListing>("JobListing", jobListingSchema);
export default JobListing;