Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit d8d75ff

Browse files
committed
[Feature] add Candidate model
1 parent 07dd39c commit d8d75ff

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/loaders/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ export default async ({ expressApp }) => {
2323
model: require('../models/user').default,
2424
};
2525

26+
const candidateModel = {
27+
name: 'userModel',
28+
// Notice the require syntax and the '.default'
29+
model: require('../models/candidate').default,
30+
};
31+
2632
// It returns the agenda instance because it's needed in the subsequent loaders
2733
await dependencyInjectorLoader({
2834
mongoConnection,
2935
models: [
3036
userModel,
37+
candidateModel,
3138
// salaryModel,
3239
// whateverModel
3340
],

src/models/candidate.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { IUser } from '../interfaces/IUser';
2+
import mongoose from 'mongoose';
3+
4+
const Candidate = new mongoose.Schema(
5+
{
6+
name: {
7+
type: String,
8+
required: [true, 'Please enter a full name'],
9+
index: true,
10+
},
11+
12+
voteCount: {
13+
type: Number,
14+
default: 0,
15+
},
16+
},
17+
{ timestamps: true },
18+
);
19+
20+
export default mongoose.model<IUser & mongoose.Document>('Candidate', Candidate);

src/models/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Model, Document } from 'mongoose';
2-
import { IUser } from '../interfaces/IUser';
2+
import { IUser, ICandidate } from '../interfaces';
33

44
export type UserModel = Model<IUser & Document>;
5+
6+
export type CandidateModel = Model<ICandidate & Document>;

0 commit comments

Comments
 (0)