Skip to content

Commit

Permalink
Merge pull request #21 from Dreallers/s01routeBackEnd
Browse files Browse the repository at this point in the history
toutes les routes series fonctionnent :)
  • Loading branch information
Tony97421 authored Dec 13, 2023
2 parents 0e60fe4 + 9d85fce commit ea06622
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
6 changes: 3 additions & 3 deletions backend/src/controllers/serieControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const read = async (req, res, next) => {
};

const edit = async (req, res, next) => {
const { id } = req.params.id;
const { id } = req.params;
req.body.id = id;
try {
const result = await tables.serie.update(req.body);
if (result.affectedRows) {
if (result) {
res.json(result);
res.sendStatus(204);
} else {
Expand All @@ -50,7 +50,7 @@ const add = async (req, res, next) => {
};

const destroy = async (req, res, next) => {
const { id } = req.params.id;
const { id } = req.params;
try {
const result = await tables.serie.delete(id);
if (result.affectedRows) {
Expand Down
42 changes: 23 additions & 19 deletions backend/src/models/SerieManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const AbstractManager = require("./AbstractManager");

class SerieManager extends AbstractManager {
constructor() {
super({ table: "Serie" });
super({ table: "serie" });
}

async create({
Expand All @@ -19,7 +19,7 @@ class SerieManager extends AbstractManager {
seasonsNumber,
}) {
const [result] = await this.database.query(
`INSERT INTO ${this.table} (miniature, title, videoUrl, duration, year, description, isAvailable, episodesNumber, seasonsNumber) values (?, ?, ?, ?, ?, ?, ?, ?)`,
`INSERT INTO ${this.table} (miniature, title, videoUrl, duration, year, description, isAvailable, episodesNumber, seasonsNumber) values (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[
miniature,
title,
Expand All @@ -42,6 +42,7 @@ class SerieManager extends AbstractManager {
);
return result;
}

async readAll() {
const [result] = await this.database.query(`select * from ${this.table} `);
return result;
Expand All @@ -60,26 +61,29 @@ class SerieManager extends AbstractManager {
seasonsNumber,
}) {
const [result] = await this.database.query(
`UPDATE ${this.table} SET miniature = ?, title = ?, videoUrl = ?, duration = ?, year = ?, description = ?, isVailable = ?, episodesNumber = ?, seasonsNumber = ?, WHERE id = ?`

`UPDATE ${this.table} SET miniature=?, title=?, videoUrl=?, duration=?, year=?, description=?, isAvailable=?, episodesNumber=?, seasonsNumber=? WHERE id=?`,
[
miniature,
title,
videoUrl,
duration,
year,
description,
isAvailable,
episodesNumber,
seasonsNumber,
id,
]
);
[
id,
miniature,
title,
videoUrl,
duration,
year,
description,
isAvailable,
episodesNumber,
seasonsNumber,
];
return result;
return result.affectedRows;

}
async delete(id) {
const [result] = await this.database.query(
`delete from ${this.table} where id = ?,`
)[id];
const result = await this.database.query(
`delete from ${this.table} where id = ?`,
[id]
);
return result;
}
}
Expand Down

0 comments on commit ea06622

Please sign in to comment.