Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production #232

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
5 changes: 4 additions & 1 deletion server/controllers/auth/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
createStudent,
putParentIdForStudentQuery,
createStudentHealthQuery,
getUserIdFromTableQuery,
} from '../../queries';

import {
Expand All @@ -20,9 +21,11 @@ import {

const putParentIdForStudent = async (child: string, parentId: number) => {
const studentUser = await findUserByEmail(child);

const studentId = studentUser?.getDataValue('id');
const studentData = await getUserIdFromTableQuery('student', studentId);

await putParentIdForStudentQuery(studentId, parentId);
await putParentIdForStudentQuery(studentData?.getDataValue('id'), parentId);
};

const signup = async (req: Request, res: Response, next: NextFunction) => {
Expand Down
5 changes: 3 additions & 2 deletions server/controllers/profiles/getParentStudent.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Response, NextFunction } from 'express';
import { getParentStudentQuery } from '../../queries';
import { getParentStudentQuery, getUserIdFromTableQuery } from '../../queries';

const getParentStudent = async (req:any, res:Response, next:NextFunction) => {
try {
const { id } = req.user;
const data = await getParentStudentQuery(id);
const parent = await getUserIdFromTableQuery('parent', id);
const data = await getParentStudentQuery(parent?.getDataValue('id'));
res.json({ msg: 'getting all student successfully', data });
} catch (error) {
next(error);
Expand Down
7 changes: 5 additions & 2 deletions server/controllers/student/putParentIdForStudent.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import { findUserByEmail, putParentIdForStudentQuery } from '../../queries';
import { findUserByEmail, putParentIdForStudentQuery, getUserIdFromTableQuery } from '../../queries';

const putParentIdForStudent = async (req: Request, res: Response, next: NextFunction) => {
try {
const { email, parentId } = req.body;
const studentUser = await findUserByEmail(email);
const studentId = studentUser?.getDataValue('id');
await putParentIdForStudentQuery(studentId, parentId);
const studentData = await getUserIdFromTableQuery('student', studentId);
const parentData = await getUserIdFromTableQuery('parent', parentId);

await putParentIdForStudentQuery(studentData?.getDataValue('id'), parentData?.getDataValue('id'));

res.json({ msg: 'student updated successfully' });
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion server/queries/profile/getParentStudentQuery.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Student, User } from '../../models';

const getParentStudentQuery = (parentId: string) => (Student.findAll({
const getParentStudentQuery = (parentId: number) => (Student.findAll({
raw: true,
where: {
parent_id: parentId,
Expand Down
2 changes: 1 addition & 1 deletion server/queries/student/putParentIdForStudentQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const putParentIdForStudentQuery = (
parentId: number,
) => Student.update({ parent_id: parentId }, {
where: {
user_id: studentId,
id: studentId,
},
});

Expand Down