-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: nouveau champ numéro de téléphone pour les utilisateurs (#1719)
- Loading branch information
1 parent
f8afb90
commit b632f8c
Showing
5 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: [email protected] - +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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ? | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }) => { | |
<label htmlFor="email">Email</label> | ||
<input className="tailwindui" placeholder="[email protected]" name="email" id="email" value={data.email} onChange={handleChange} /> | ||
</div> | ||
<div className="tw-flex tw-basis-1/2 tw-flex-col tw-px-4 tw-py-2"> | ||
<label htmlFor="phone">Téléphone</label> | ||
<input className="tailwindui" placeholder="0612345678" name="phone" id="phone" value={data.phone} onChange={handleChange} /> | ||
</div> | ||
<div className="tw-flex tw-basis-1/2 tw-flex-col tw-px-4 tw-py-2"> | ||
<label htmlFor="role">Role</label> | ||
<div className="tw-mt-1 tw-w-full"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters