Skip to content

Commit

Permalink
Merge pull request #101 from WildCodeSchool/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Gwada authored Jan 25, 2024
2 parents 33da72b + 630b653 commit d05e7a3
Show file tree
Hide file tree
Showing 49 changed files with 1,548 additions and 1,135 deletions.
1 change: 1 addition & 0 deletions backend/database/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const client = mysql.createPool({
user: DB_USER,
password: DB_PASSWORD,
database: DB_NAME,
dateStrings: true,
});

// Try to get a connection to the database
Expand Down
343 changes: 129 additions & 214 deletions backend/database/database.sql

Large diffs are not rendered by default.

Binary file not shown.
146 changes: 66 additions & 80 deletions backend/src/controllers/courseControllers.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,89 @@
const models = require("../models/index");

const getCourse = (_, res) => {
models.course
.findAll()
.then((rows) => {
res.send(rows);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
const getCourse = async (_, res) => {
try {
const rows = await models.course.findAll();
res.send(rows);
} catch (err) {
console.error(err);
res.sendStatus(500);
}
};

const getCoursesByCvId = (req, res) => {
models.experience
.findAllByCvId(req.params.id)
.then((rows) => {
res.send(rows);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
const getCoursesByCvId = async (req, res) => {
try {
const rows = await models.course.findAllByCvId(req.params.id);
res.send(rows);
} catch (err) {
console.error(err);
res.sendStatus(500);
}
};

const getCourseById = (req, res) => {
const id = parseInt(req.params.id, 10);

models.course
.findId(id)
.then(([item]) => {
if (item[0] != null) {
res.json(item[0]);
} else {
res.sendStatus(404);
}
})
.catch((err) => {
console.error(err);
res.sendStatus(422);
});
const getCourseById = async (req, res) => {
try {
const id = parseInt(req.params.id, 10);
const [item] = await models.course.findId(id);
if (item[0] != null) {
res.json(item[0]);
} else {
res.sendStatus(404);
}
} catch (err) {
console.error(err);
res.sendStatus(422);
}
};

const postCourse = (req, res) => {
models.course
.create(req.body)
.then((rows) => {
res.send({
id: rows.insertId,
domaine: req.body.domaine,
name: req.body.name,
});
})
.catch((err) => {
console.error(err);
res.status(422).send({ error: err.message });
const postCourse = async (req, res) => {
try {
const rows = await models.course.create(req.body);
res.send({
id: rows.insertId,
domaine: req.body.domaine,
name: req.body.name,
});
// res.status(418).send(req.body)
} catch (err) {
console.error(err);
res.status(422).send({ error: err.message });
}
};

const updateCourse = async (req, res) => {
const id = parseInt(req.params.id, 10);
if (!id) {
res.sendStatus(500);
}
// const updateCourse = async (req, res) => {
// try {
// const id = parseInt(req.params.id, 10);
// if (!id) {
// res.sendStatus(500);
// }

models.course
.update(id, req.body)
.then((result) => {
if (result.affectedRows === 0) {
res.sendStatus(500);
}
res.sendStatus(200);
})
.catch((error) => {
console.error(error);
res.status(422).send({ error: error.message });
});
};
// const result = await models.course.update(id, req.body);
// if (result.affectedRows === 0) {
// res.sendStatus(500);
// }
// res.sendStatus(200);
// } catch (error) {
// console.error(error);
// res.status(422).send({ error: error.message });
// }
// };

const deleteCourseById = (req, res) => {
const id = parseInt(req.params.id, 10);
const deleteCourseById = async (req, res) => {
try {
const id = parseInt(req.params.id, 10);

models.course
.deleteId(id)
.then(([result]) => {
res.status(201).send({ message: result });
})
.catch((err) => {
console.error(err);
res.status(422).send({ message: "Course not found." });
});
const [result] = await models.course.deleteId(id);
res.status(201).send({ message: result });
} catch (err) {
console.error(err);
res.status(422).send({ message: "Course not found." });
}
};

module.exports = {
getCourse,
getCourseById,
postCourse,
updateCourse,
// updateCourse,
deleteCourseById,
getCoursesByCvId,
};
25 changes: 11 additions & 14 deletions backend/src/controllers/cvControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const models = require("../models/index");
const getCv = async (req, res) => {
const userId = parseInt(req.params.id, 10);
if (userId !== req.user.id) {
return res.status(403).send({ message: "Invalid user" });
return res.status(403).send({ message: "Invalid user" }); // <=== Ton erreur vient d'ici
}
try {
const [item] = await models.cv.findCvByUserId(userId);
Expand All @@ -25,20 +25,17 @@ const getCv = async (req, res) => {
}
};

const postCv = (req, res) => {
models.cv
.create(req.body)
.then((rows) => {
res.send({
id: rows.insertId,
userId: rows.user_id,
});
})
.catch((err) => {
console.error(err);
res.status(422).send({ error: err.message });
const postCv = async (req, res) => {
try {
const rows = await models.cv.create(req.body);
res.send({
id: rows.insertId,
userId: rows.user_id,
});
// res.status(418).send(req.body)
} catch (err) {
console.error(err);
res.status(422).send({ error: err.message });
}
};

module.exports = { postCv, getCv };
142 changes: 64 additions & 78 deletions backend/src/controllers/experienceControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,102 +5,88 @@ const models = require("../models/index");
// return jwt.sign(data, process.env.APP_SECRET);
// }

const getExperiences = (_, res) => {
models.experience
.findAll()
.then((rows) => {
res.send(rows);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
const getExperiences = async (_, res) => {
try {
const rows = await models.experience.findAll();
res.send(rows);
} catch (err) {
console.error(err);
res.sendStatus(500);
}
};

const getExperiencesByCvId = (req, res) => {
models.experience
.findAllByCvId(req.params.id)
.then((rows) => {
res.send(rows);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
const getExperiencesByCvId = async (req, res) => {
try {
const rows = await models.experience.findAllByCvId(req.params.id);
res.send(rows);
} catch (err) {
console.error(err);
res.sendStatus(500);
}
};

const getExperienceById = (req, res) => {
const id = parseInt(req.params.id, 10);

models.experience
.findId(id)
.then(([item]) => {
if (item[0] != null) {
res.json(item[0]);
} else {
res.sendStatus(404);
}
})
.catch((err) => {
console.error(err);
res.sendStatus(422);
});
const getExperienceById = async (req, res) => {
try {
const id = parseInt(req.params.id, 10);
const [item] = await models.experience.findId(id);
if (item[0] != null) {
res.json(item[0]);
} else {
res.sendStatus(404);
}
} catch (err) {
console.error(err);
res.sendStatus(422);
}
};

const postExperience = (req, res) => {
models.experience
.create(req.body)
.then((rows) => {
res.send({
id: rows.insertId,
});
})
.catch((err) => {
console.error(err);
res.status(422).send({ error: err.message });
const postExperience = async (req, res) => {
try {
const rows = await models.experience.create(req.body);
res.send({
id: rows.insertId,
});
// res.status(418).send(req.body)
} catch (err) {
console.error(err);
res.status(422).send({ error: err.message });
}
};

const updateExperience = async (req, res) => {
const id = parseInt(req.params.id, 10);
if (!id) {
res.sendStatus(500);
}
// const updateExperience = async (req, res) => {
// try {
// const id = parseInt(req.params.id, 10);
// if (!id) {
// res.sendStatus(500);
// }

models.experience
.update(id, req.body)
.then((result) => {
if (result.affectedRows === 0) {
res.sendStatus(500);
}
res.sendStatus(200);
})
.catch((error) => {
console.error(error);
res.status(422).send({ error: error.message });
});
};
// const result = await models.experience.update(id, req.body);
// if (result.affectedRows === 0) {
// res.sendStatus(500);
// }
// res.sendStatus(200);
// } catch (error) {
// console.error(error);
// res.status(422).send({ error: error.message });
// }
// };

const deleteExperienceById = (req, res) => {
const id = parseInt(req.params.id, 10);
const deleteExperienceById = async (req, res) => {
try {
const id = parseInt(req.params.id, 10);

models.experience
.deleteId(id)
.then(([result]) => {
res.status(201).send({ message: result });
})
.catch((err) => {
console.error(err);
res.status(422).send({ message: "Experience not found." });
});
const [result] = await models.experience.deleteId(id);
res.status(201).send({ message: result });
} catch (err) {
console.error(err);
res.status(422).send({ message: "Experience not found." });
}
};

module.exports = {
getExperiences,
getExperienceById,
postExperience,
updateExperience,
// updateExperience,
deleteExperienceById,
getExperiencesByCvId,
};
Loading

0 comments on commit d05e7a3

Please sign in to comment.