|
|
@ -825,7 +825,6 @@ exports.updateTeamMember = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.createstaff = async (request, reply) => {
|
|
|
|
exports.createstaff = async (request, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { customerId } = request.params;
|
|
|
|
const { customerId } = request.params;
|
|
|
@ -842,13 +841,30 @@ exports.createstaff = async (request, reply) => {
|
|
|
|
return reply.status(404).send({ error: 'Customer not found' });
|
|
|
|
return reply.status(404).send({ error: 'Customer not found' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Validate each staff entry and append it to the user's staff array
|
|
|
|
// Check for duplicate phone numbers
|
|
|
|
const newStaff = staff.map((member) => ({
|
|
|
|
const existingPhones = new Set(user.staff.staff.map((member) => member.phone));
|
|
|
|
name: member.name || null,
|
|
|
|
const newStaff = [];
|
|
|
|
phone: member.phone || null,
|
|
|
|
const duplicatePhones = [];
|
|
|
|
password: member.password || null,
|
|
|
|
|
|
|
|
status: "active", // Default status
|
|
|
|
staff.forEach((member) => {
|
|
|
|
}));
|
|
|
|
if (member.phone && existingPhones.has(member.phone)) {
|
|
|
|
|
|
|
|
duplicatePhones.push(member.phone);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (member.phone) {
|
|
|
|
|
|
|
|
existingPhones.add(member.phone);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
newStaff.push({
|
|
|
|
|
|
|
|
name: member.name || null,
|
|
|
|
|
|
|
|
phone: member.phone || null,
|
|
|
|
|
|
|
|
password: member.password || null,
|
|
|
|
|
|
|
|
status: "active", // Default status
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (duplicatePhones.length > 0) {
|
|
|
|
|
|
|
|
return reply.status(400).send({ error: 'Duplicate phone numbers found', duplicatePhones });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update the user document with the new staff members
|
|
|
|
// Update the user document with the new staff members
|
|
|
|
user.staff.staff.push(...newStaff);
|
|
|
|
user.staff.staff.push(...newStaff);
|
|
|
@ -864,6 +880,7 @@ exports.createstaff = async (request, reply) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.editStaff = async (request, reply) => {
|
|
|
|
exports.editStaff = async (request, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { customerId, phone } = request.params;
|
|
|
|
const { customerId, phone } = request.params;
|
|
|
|