- Added profile submission handling

This commit is contained in:
2018-06-03 16:39:10 -04:00
parent d4ff498789
commit 9ed024e86d
4 changed files with 52 additions and 14 deletions

View File

@@ -1,3 +1,4 @@
const EventEmitter = require('events');
const Images = require('../modules/images');
const Logger = require('../modules/logger');
const Messages = require('../models/message');
@@ -8,26 +9,16 @@ const ProfileSchema = new Mongoose.Schema({
"details": {
"about": { type: String },
"age": { type: Number, index: true, default: 0 },
"body": { type: String, enum: ['dns','slim','toned','average','muscular','large','stocky'], default: 'dns' },
"ethnicity": { type: String, enum: ['dns','asian','black','latino','middle eastern','mixed','native american','white','south asian','other'], default: 'dns' },
"gender": { type: String, enum: ['man','cis man','trans man','woman','cis woman','trans woman','non-binary','non-conforming','queer','crossdresser'] },
"height": { type: String },
"looking": [{ type: String, enum: ['chat','friends','networking','dates','relationship','right now'] }],
"location": { type: String },
"name": { type: String, index: true },
"pic": {
"detail": { type: String, default: "profile/default_detail.png" },
"thumb": { type: String, default: "profile/default_thumbnail.png" }
},
"position": { type: String, enum: ['dns','bottom','vers bottom','versatile','vers top','top'], default: 'dns' },
"pronouns": { type: String },
"weight": { type: Number },
"relationship": { type: String, enum: ['dns','committed','dating','engaged','exclusive','married','open relationship','partnered','single'], default: 'dns' },
"status": { type: String, enum: ['dns','unknown','negative','negative, on prep','postive','positive, undetectable'], default: 'dns' },
"tested": { type: Date },
"tribe": [{ type: String, enum: ['twink','trans','poz','leather','geek','discreet','otter','bear','daddy','jock','clean-cut'] }]
}
},
"messages": [ { type: Messages.schema } ],
"submitted": { type: Boolean, default: false }
"submitted": { type: Boolean, default: false },
"approved": { type: Boolean, default: false }
});
ProfileSchema.pre('findOneAndUpdate', function (next) {
@@ -491,6 +482,31 @@ module.exports = {
});
},
processSubmission: (e, profile) => {
var ProfileEvents = new EventEmitter();
var temp = JSON.parse(profile.profile);
var insert = {
details: temp.details,
messages: temp.messages,
submitted: true,
approved: false
};
insert.details.pic = { detail: profile.image };
ProfileEvents.once('create', (err, result) => {
if (err) {
e.emit('processSubmission', err, null);
}
if (result) {
e.emit('processSubmission', null, result);
}
});
module.exports.create(ProfileEvents, insert);
},
update: (e, profileId, profile) => {
const promise = new Promise((resolve, reject) => {
ProfileModel.findOneAndUpdate(