generated from WildCodeSchool/create-js-monorepo
-
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.
Merge pull request #101 from WildCodeSchool/dev
Dev
- Loading branch information
Showing
49 changed files
with
1,548 additions
and
1,135 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
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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 |
---|---|---|
@@ -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, | ||
}; |
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
Oops, something went wrong.