From d5b34dc81f88a0e2d4026c7edd0ed324f19b3d7d Mon Sep 17 00:00:00 2001 From: Mike Fitzpatrick Date: Wed, 10 Jul 2019 23:45:46 -0400 Subject: [PATCH] - Tweaks --- fixtures/item.js | 7 +++++-- models/user.js | 25 +++++++++++++++++++++++-- routes/demo.js | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/fixtures/item.js b/fixtures/item.js index 364e105..87143cb 100644 --- a/fixtures/item.js +++ b/fixtures/item.js @@ -64,7 +64,7 @@ const item = ({ }; }; -const getItems = ({ +const getDemoData = ({ eventId = faker.random.uuid(), auction = 10, ticket = 4, @@ -120,4 +120,7 @@ const getItems = ({ return items; }; -module.exports = getItems; +module.exports = { + getDemoData, + item, +}; diff --git a/models/user.js b/models/user.js index 67d7dd5..d808272 100644 --- a/models/user.js +++ b/models/user.js @@ -66,8 +66,8 @@ const UserSchema = new mongoose.Schema( trim: true, }, - address: [ AddressSchema ], - phone: [ PhoneSchema ], + addresses: [ AddressSchema ], + phones: [ PhoneSchema ], credentials: [ LoginSchema ], tokenCheckBit: { @@ -256,6 +256,27 @@ UserSchema.methods.toAuthJSON = function () { }; }; +UserSchema.methods.toProfileJSON = function () { + const hasNomDeBid = !!this.nomDeBid; + const nomDeBid = this.getNomDeBid(); + + return { + addresses: this.addresses, + avatar: this.avatar, + email: this.email, + firstName: this.firstName, + generatedNomDeBid: !hasNomDeBid, + isAllowedToBid: this.isAllowedToBid, + isOrganizationEmployee: this.isOrganizationEmployee, + isVerified: this.isVerified, + lastName: this.lastName, + nomDeBid: nomDeBid, + organizationIdentifier: this.organizationIdentifier, + paymentToken: this.paymentToken, + phones: this.phones, + }; +}; + UserSchema.methods.validatePassword = function (password) { const strategy = this.getAuthStrategy('local'); diff --git a/routes/demo.js b/routes/demo.js index d3c34e2..af51742 100644 --- a/routes/demo.js +++ b/routes/demo.js @@ -49,7 +49,7 @@ module.exports = function (server, auth) { return next(err, false, 'There was a problem creating the event'); } - const itemsStub = ItemFixture({ + const itemsStub = ItemFixture.getDemoData({ eventId: event.id, auction: 10, ticket: eventTickets,