我需要一些帮助来找到在我正在做的项目中注册新记录的最佳方法。 在这个项目中,有 3 个配置文件(Admin、Leader 和 Member)可以注册医生。在 doctors 表中,我有一个名为 team 的列。这个想法是放置医生将加入的团队的 ID。 因此,在医生的记录中,我需要确定哪个用户在进行记录:如果是 Leader 或 Member,则 team 列将收到用户所属的 Team 的 ID。 如果是管理员,则列将为空白,因为管理员管理所有团队。我已经创建了一个“副本”文件来显示我正在尝试做的事情。在原始文件中,我可以将医生的记录保存在表中,但我需要识别哪个用户正在创建记录,以便时间列接收用户 ID(成员或领导)。
class DoctorController {
createDoctor = async (req, res, next) => {
const { teamId, userId } = req.body;
const image = req.file && req.file.filename;
const { name, email, address, mobile, specialty1, specialty2, specialty3, subspecialty, patient_type, sus, last_visit, tj, hid, team } = req.body;
if (!name || !email || !mobile) return next(ErrorHandler.badRequest('Campos obrigatórios'));
type = type.toLowerCase();
if (type === 'admin') {
name,
email,
address,
mobile,
image,
specialty1,
specialty2,
specialty3,
subspecialty,
patient_type,
sus,
last_visit,
tj,
hid
}
const doctor = {
name, email, address, mobile, specialty1, specialty2, specialty3, subspecialty, patient_type, sus, last_visit, tj, hid
}
if (type === 'leader' || 'member') {
name,
email,
address,
mobile,
image,
specialty1,
specialty2,
specialty3,
subspecialty,
patient_type,
sus,
last_visit,
tj,
hid,
team = userModel.findById(userId).populate({ teamId })
}
const doctorResp = await doctorService.createDoctor(doctor);
if (!doctorResp) return next(ErrorHandler.serverError('Erro ao cadastrar o médico'));
res.json({ success: true, message: 'Médico cadastrado com sucesso', doctor: new DoctorDto(doctor) });
}
回购:https://github.com/zaratt/HLC/tree/main/Backend
目标:确定创建记录的用户配置文件