diff --git a/api/src/controllers/user.js b/api/src/controllers/user.js index 5532569c4..fad3bfe97 100644 --- a/api/src/controllers/user.js +++ b/api/src/controllers/user.js @@ -308,6 +308,7 @@ router.post( try { z.object({ name: z.string().optional(), + phone: z.string().optional(), email: z.preprocess((email) => email.trim().toLowerCase(), z.string().email().optional().or(z.literal(""))), healthcareProfessional: z.boolean(), team: z.array(z.string().regex(looseUuidRegex)), @@ -319,10 +320,11 @@ router.post( return next(error); } - const { name, email, role, team, healthcareProfessional } = req.body; + const { name, email, role, team, healthcareProfessional, phone } = req.body; const token = crypto.randomBytes(20).toString("hex"); const newUser = { name: sanitizeAll(name), + phone: sanitizeAll(phone) || null, role, healthcareProfessional: role === "restricted-access" ? false : healthcareProfessional, email: sanitizeAll(email.trim().toLowerCase()), @@ -376,6 +378,7 @@ Guillaume Demirhan, porteur du projet: g.demirhan@aurore.asso.fr - +33 7 66 56 1 data: { _id: data._id, name: data.name, + phone: data.phone, email: data.email, role: data.role, healthcareProfessional: data.healthcareProfessional, @@ -432,6 +435,7 @@ router.post( user: { _id: userWithoutPassword._id, name: userWithoutPassword.name, + phone: userWithoutPassword.phone, email: userWithoutPassword.email, createdAt: userWithoutPassword.createdAt, updatedAt: userWithoutPassword.updatedAt, @@ -469,6 +473,7 @@ router.get( data: { _id: user._id, name: user.name, + phone: user.phone, email: user.email, createdAt: user.createdAt, updatedAt: user.updatedAt, @@ -511,6 +516,7 @@ router.get( data.push({ _id: user._id, name: user.name, + phone: user.phone, email: user.email, createdAt: user.createdAt, updatedAt: user.updatedAt, @@ -535,6 +541,7 @@ router.put( try { z.object({ name: z.optional(z.string().min(1)), + phone: z.string().optional(), email: z.preprocess((email) => email.trim().toLowerCase(), z.string().email().optional().or(z.literal(""))), password: z.optional(z.string().min(1)), gaveFeedbackEarly2023: z.optional(z.boolean()), @@ -548,12 +555,13 @@ router.put( } const _id = req.user._id; - const { name, email, password, team, termsAccepted, gaveFeedbackEarly2023 } = req.body; + const { name, email, password, team, termsAccepted, gaveFeedbackEarly2023, phone } = req.body; const user = await User.findOne({ where: { _id } }); if (!user) return res.status(404).send({ ok: false, error: "Utilisateur non trouvé" }); if (name) user.set({ name: sanitizeAll(name) }); + if (phone) user.set({ phone: sanitizeAll(phone) }); if (email) user.set({ email: sanitizeAll(email.trim().toLowerCase()) }); if (termsAccepted) user.set({ termsAccepted: termsAccepted }); if (password) { @@ -579,6 +587,7 @@ router.put( user: { _id: user._id, name: user.name, + phone: user.phone, email: user.email, createdAt: user.createdAt, updatedAt: user.updatedAt, @@ -604,6 +613,7 @@ router.put( }), body: z.object({ name: z.optional(z.string().min(1)), + phone: z.string().optional(), email: z.optional(z.preprocess((email) => email.trim().toLowerCase(), z.string().email().optional().or(z.literal("")))), password: z.optional(z.string().min(1)), team: z.optional(z.array(z.string().regex(looseUuidRegex))), @@ -617,12 +627,13 @@ router.put( } const _id = req.params._id; - const { name, email, team, role, healthcareProfessional } = req.body; + const { name, email, team, role, healthcareProfessional, phone } = req.body; const user = await User.findOne({ where: { _id, organisation: req.user.organisation } }); if (!user) return res.status(404).send({ ok: false, error: "Not Found" }); if (name) user.name = sanitizeAll(name); + if (phone) user.phone = sanitizeAll(phone); if (email) user.email = sanitizeAll(email.trim().toLowerCase()); if (healthcareProfessional !== undefined) user.set({ healthcareProfessional }); @@ -647,6 +658,7 @@ router.put( user: { _id: user._id, name: user.name, + phone: user.phone, email: user.email, createdAt: user.createdAt, updatedAt: user.updatedAt, diff --git a/api/src/db/migrations/20231010095801-add-phone-to-user.js b/api/src/db/migrations/20231010095801-add-phone-to-user.js new file mode 100644 index 000000000..0c15ecf56 --- /dev/null +++ b/api/src/db/migrations/20231010095801-add-phone-to-user.js @@ -0,0 +1,15 @@ +"use strict"; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.sequelize.query(` + ALTER TABLE "mano"."User" + ADD COLUMN IF NOT EXISTS "phone" text; + `); + }, + + async down() { + // Qui fait des down, et pourquoi ? + }, +}; diff --git a/api/src/models/user.js b/api/src/models/user.js index ac7b39f96..3b60d068c 100644 --- a/api/src/models/user.js +++ b/api/src/models/user.js @@ -5,6 +5,7 @@ module.exports = (sequelize, DataTypes) => { const schema = { _id: { type: DataTypes.UUID, allowNull: false, defaultValue: DataTypes.UUIDV4, primaryKey: true }, name: DataTypes.TEXT, + phone: DataTypes.TEXT, email: { type: DataTypes.TEXT, allowNull: false }, password: { type: DataTypes.TEXT, allowNull: false }, organisation: { type: DataTypes.UUID, references: { model: "Organisation", key: "_id", deferrable: Deferrable.INITIALLY_IMMEDIATE } }, diff --git a/dashboard/src/scenes/user/list.js b/dashboard/src/scenes/user/list.js index d0d4c5c6a..fa60889c2 100644 --- a/dashboard/src/scenes/user/list.js +++ b/dashboard/src/scenes/user/list.js @@ -92,6 +92,14 @@ const List = () => { sortOrder, sortBy, }, + { + title: 'Téléphone', + dataKey: 'phone', + onSortOrder: setSortOrder, + onSortBy: setSortBy, + sortOrder, + sortBy, + }, { title: 'Rôle', dataKey: 'role', @@ -121,6 +129,7 @@ const List = () => { ); }, }, + { title: 'Créé le', dataKey: 'createdAt', @@ -154,6 +163,7 @@ const Create = ({ onChange, users }) => { return { name: '', email: '', + phone: '', role: 'normal', team: teams.map((t) => t._id), healthcareProfessional: false, @@ -226,6 +236,10 @@ const Create = ({ onChange, users }) => { +