gpt4 book ai didi

javascript - 一种型号的两个版本

转载 作者:行者123 更新时间:2023-12-03 02:16:12 24 4
gpt4 key购买 nike

这有点奇怪,但我需要在 Node.js 中拥有同一模型的两个版本。我会尽力解释。

我必须根据他们是求职者还是雇主的事实创建两种不同的 acc 类型。这些字段非常不同,我无法真正更改它们。

var mongoose = require('mongoose');
var plm = require('passport-local-mongoose');
var accountSchema = new mongoose.Schema({
username: String,
accType: String,
companyName: String,
contactPersonFullName: String,
email: String,
companyWebsite: String,
city: String,
province: String,
postalCode: String,
phoneNumber: String,
hiringRegion: String[], // TODO
description: String,
logo: String, //TODO
workingWithEOESC: Boolean,
industry: String,
});
accountSchema.plugin(plm);
module.exports = mongoose.model('account-employer', accountSchema);

这 ^ 是我的雇主帐户模型。这是我的求职者模型:

var mongoose = require('mongoose');
var plm = require('passport-local-mongoose');
var accountSchema = new mongoose.Schema({
username: String,
accType: String,
city: String,
province: String,
postalCode: String,
phone: String,
ageGroup: String,
education: String,
lookingForWork: Boolean,
employmentStatus: String,
workingWithEOESC: Boolean,
resume: String, //TODO
mainWorkExp: String,
});
accountSchema.plugin(plm);
module.exports = mongoose.model('account-seeker', accountSchema);

我认为这是个好主意,但后来我意识到我需要一个帐户模型,因为passport在 Express 中的工作方式。如何确保不同的用户类型在 NoSQL 数据库中具有不同的字段和信息,同时保留一个帐户登录和注册?我现在可能毫无意义,但我找不到摆脱这种情况的方法。

最佳答案

var mongoose = require('mongoose');
var plm = require('passport-local-mongoose');
var userSchema = new mongoose.Schema({
accType: String,
companyName: String,
contactPersonFullName: String,
email: String,
companyWebsite: String,
city: String,
province: String,
postalCode: String,
hiringRegion: String[], // TODO
description: String,
logo: String, //TODO
workingWithEOESC: Boolean,
industry: String,
phone: String,
ageGroup: String,
education: String,
lookingForWork: Boolean,
employmentStatus: String,
resume: String, //TODO
mainWorkExp: String,
isEmployer: Boolean // added this one to distinguish between employer and employee
});
userSchema.plugin(plm);
module.exports = mongoose.model('User', userSchema);

为什么不将它们合并到一个架构中并添加一个字段来检查这是否是雇员和雇主。

关于javascript - 一种型号的两个版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49367839/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com