Skip to content

Commit

Permalink
Fix toJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
msohaill committed Jun 6, 2024
1 parent 71a522c commit a378d76
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 61 deletions.
4 changes: 2 additions & 2 deletions models/account.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const AccountSchema = new mongoose.Schema({
}
});

AccountSchema.methods.toJSON = function() {
const as = this.toObject();
AccountSchema.methods.toJSON = function(options) {
const as = this.toObject(options);
delete as.__v;
as.id = as._id;
delete as._id;
Expand Down
12 changes: 6 additions & 6 deletions models/accountConfirmationToken.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const AccountConfirmationSchema = new mongoose.Schema({
}
});

AccountConfirmationSchema.methods.toJSON = function() {
const resetObj = this.toObject();
delete resetObj.__v;
resetObj.id = resetObj._id;
delete resetObj._id;
return resetObj;
AccountConfirmationSchema.methods.toJSON = function(options) {
const acs = this.toObject(options);
delete acs.__v;
acs.id = acs._id;
delete acs._id;
return acs;
};

module.exports = mongoose.model(
Expand Down
4 changes: 2 additions & 2 deletions models/bus.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const BusSchema = new mongoose.Schema({
}
});

BusSchema.methods.toJSON = function() {
const bs = this.toObject();
BusSchema.methods.toJSON = function(options) {
const bs = this.toObject(options);
delete bs.__v;
bs.id = bs._id;
delete bs._id;
Expand Down
12 changes: 6 additions & 6 deletions models/emailTemplate.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const EmailTemplateSchema = new mongoose.Schema({
}
});

EmailTemplateSchema.methods.toJSON = function () {
const emailTemplateObj = this.toObject();
delete emailTemplateObj.__v;
emailTemplateObj.id = emailTemplateObj._id;
delete emailTemplateObj._id;
return emailTemplateObj;
EmailTemplateSchema.methods.toJSON = function (options) {
const ets = this.toObject(options);
delete ets.__v;
ets.id = ets._id;
delete ets._id;
return ets;
};

// export the model
Expand Down
4 changes: 2 additions & 2 deletions models/hacker.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ const HackerSchema = new mongoose.Schema({
}
});

HackerSchema.methods.toJSON = function() {
const hs = this.toObject();
HackerSchema.methods.toJSON = function(options) {
const hs = this.toObject(options);
delete hs.__v;
hs.id = hs._id;
delete hs._id;
Expand Down
12 changes: 6 additions & 6 deletions models/passwordResetToken.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const passwordResetSchema = new mongoose.Schema({
}
});

passwordResetSchema.methods.toJSON = function() {
const resetObj = this.toObject();
delete resetObj.__v;
resetObj.id = resetObj._id;
delete resetObj._id;
return resetObj;
passwordResetSchema.methods.toJSON = function(options) {
const prs = this.toObject(options);
delete prs.__v;
prs.id = prs._id;
delete prs._id;
return prs;
};

module.exports = mongoose.model("PasswordResetToken", passwordResetSchema);
12 changes: 6 additions & 6 deletions models/role.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ const RoleSchema = new mongoose.Schema({
]
});

RoleSchema.methods.toJSON = function() {
const ps = this.toObject();
delete ps.__v;
ps.id = ps._id;
delete ps._id;
return ps;
RoleSchema.methods.toJSON = function(options) {
const rs = this.toObject(options);
delete rs.__v;
rs.id = rs._id;
delete rs._id;
return rs;
};
//export the model
module.exports = mongoose.model("Role", RoleSchema);
12 changes: 6 additions & 6 deletions models/roleBinding.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const roleBinding = new mongoose.Schema({
}
});

roleBinding.methods.toJSON = function() {
const ps = this.toObject();
delete ps.__v;
ps.id = ps._id;
delete ps._id;
return ps;
roleBinding.methods.toJSON = function(options) {
const rb = this.toObject(options);
delete rb.__v;
rb.id = rb._id;
delete rb._id;
return rb;
};
//export the model
module.exports = mongoose.model("RoleBinding", roleBinding);
4 changes: 2 additions & 2 deletions models/settings.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const settings = new mongoose.Schema({
}
});

settings.methods.toJSON = function() {
const ss = this.toObject();
settings.methods.toJSON = function(options) {
const ss = this.toObject(options);
delete ss.__v;
ss.id = ss._id;
delete ss._id;
Expand Down
4 changes: 2 additions & 2 deletions models/sponsor.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const SponsorSchema = new mongoose.Schema({
]
});

SponsorSchema.methods.toJSON = function() {
const ss = this.toObject();
SponsorSchema.methods.toJSON = function(options) {
const ss = this.toObject(options);
delete ss.__v;
ss.id = ss._id;
delete ss._id;
Expand Down
4 changes: 2 additions & 2 deletions models/staff.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const StaffSchema = new mongoose.Schema({
}
});

StaffSchema.methods.toJSON = function() {
const ss = this.toObject();
StaffSchema.methods.toJSON = function(options) {
const ss = this.toObject(options);
delete ss.__v;
ss.id = ss._id;
delete ss._id;
Expand Down
4 changes: 2 additions & 2 deletions models/team.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function validateTeamSize(membersArr) {
return membersArr.length <= Constants.MAX_TEAM_SIZE;
}

TeamSchema.methods.toJSON = function() {
const ts = this.toObject();
TeamSchema.methods.toJSON = function(options) {
const ts = this.toObject(options);
delete ts.__v;
ts.id = ts._id;
delete ts._id;
Expand Down
12 changes: 6 additions & 6 deletions models/travel.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const TravelSchema = new mongoose.Schema({
}
});

TravelSchema.methods.toJSON = function() {
const hs = this.toObject();
delete hs.__v;
hs.id = hs._id;
delete hs._id;
return hs;
TravelSchema.methods.toJSON = function(options) {
const ts = this.toObject(options);
delete ts.__v;
ts.id = ts._id;
delete ts._id;
return ts;
};

//export the model
Expand Down
4 changes: 2 additions & 2 deletions models/volunteer.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const VolunteerSchema = new mongoose.Schema({
}
});

VolunteerSchema.methods.toJSON = function() {
const vs = this.toObject();
VolunteerSchema.methods.toJSON = function(options) {
const vs = this.toObject(options);
delete vs.__v;
vs.id = vs._id;
delete vs._id;
Expand Down
18 changes: 9 additions & 9 deletions tests/hacker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("GET hacker", function() {
let hacker = new Hacker(TeamHacker0);
chai.assert.deepStrictEqual(
res.body.data,
JSON.parse(JSON.stringify(hacker)),
hacker.toJSON({ flattenObjectIds: true}),
);
done();
});
Expand Down Expand Up @@ -186,7 +186,7 @@ describe("GET hacker", function() {
let hacker = new Hacker(TeamHacker0);
chai.assert.deepStrictEqual(
res.body.data,
JSON.parse(JSON.stringify(hacker)),
hacker.toJSON({ flattenObjectIds: true }),
);

done();
Expand Down Expand Up @@ -222,7 +222,7 @@ describe("GET hacker", function() {

chai.assert.deepStrictEqual(
res.body.data,
JSON.parse(JSON.stringify(hacker)),
hacker.toJSON({ flattenObjectIds: true }),
);

done();
Expand Down Expand Up @@ -312,7 +312,7 @@ describe("GET hacker", function() {
let hacker = new Hacker(TeamHacker0);
chai.assert.deepStrictEqual(
res.body.data,
JSON.parse(JSON.stringify(hacker))
hacker.toJSON({ flattenObjectIds: true }),
);

done();
Expand Down Expand Up @@ -348,7 +348,7 @@ describe("GET hacker", function() {

chai.assert.deepStrictEqual(
res.body.data,
JSON.parse(JSON.stringify(hacker))
hacker.toJSON({ flattenObjectIds: true }),
);

done();
Expand Down Expand Up @@ -445,13 +445,13 @@ describe("POST create hacker", function() {
// create JSON version of model
// delete id as they will be different between model objects
// update status to be applied on the comparator hacker object
const hacker = new Hacker(newHacker0).toJSON();
const hacker = new Hacker(newHacker0).toJSON({ flattenObjectIds: true });
hacker.status = Constants.General.HACKER_STATUS_APPLIED;
delete res.body.data.id;
delete hacker.id;
chai.assert.deepStrictEqual(
res.body.data,
JSON.parse(JSON.stringify(hacker)),
hacker,
"objects do not match"
);

Expand Down Expand Up @@ -483,13 +483,13 @@ describe("POST create hacker", function() {
// create JSON version of model
// delete id as they will be different between model objects
// update status to be applied on the comparator hacker object
const hacker = new Hacker(newHacker0).toJSON();
const hacker = new Hacker(newHacker0).toJSON({ flattenObjectIds: true });
hacker.status = Constants.General.HACKER_STATUS_APPLIED;
delete res.body.data.id;
delete hacker.id;
chai.assert.deepStrictEqual(
res.body.data,
JSON.parse(JSON.stringify(hacker)),
hacker,
);
done();
});
Expand Down

0 comments on commit a378d76

Please sign in to comment.