-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42f513c
commit 2ef87ae
Showing
2 changed files
with
71 additions
and
0 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
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,51 @@ | ||
import { getUserByEmail, patientEdit } from "@server/mongodb/actions/User"; | ||
import APIWrapper from "@server/utils/APIWrapper"; | ||
import { IUser } from "@/common_utils/types"; | ||
|
||
interface EditData { | ||
email: string; | ||
firstName: string; | ||
lastName: string; | ||
phoneNumber: string; | ||
birthDate: string; | ||
} | ||
|
||
export const POST = APIWrapper({ | ||
config: { | ||
requireToken: false, | ||
}, | ||
handler: async (req) => { | ||
const editData: EditData = (await req.json()) as EditData; | ||
|
||
if (!editData) { | ||
throw new Error("Missing request data"); | ||
} | ||
|
||
if ( | ||
editData.birthDate === undefined || | ||
editData.email === undefined || | ||
editData.firstName === undefined || | ||
editData.lastName === undefined || | ||
editData.phoneNumber === undefined | ||
) { | ||
throw new Error("Missing parameter(s)"); | ||
} | ||
|
||
const user = await getUserByEmail(editData.email); | ||
if (!user) { | ||
throw new Error("User not found."); | ||
} | ||
|
||
const newSignUp = await patientEdit({ | ||
email: editData.email, | ||
firstName: editData.firstName, | ||
lastName: editData.lastName, | ||
phoneNumber: editData.phoneNumber, | ||
birthDate: editData.birthDate, | ||
} as Omit< | ||
IUser, | ||
"chapter" | "location" | "patientDetails" | "new" | "signedUp" | "role" | ||
>); | ||
return newSignUp; | ||
}, | ||
}); |