diff --git a/graphql/resolvers/annonce.js b/graphql/resolvers/annonce.js index decce585c8592f9bbd81398d6ae12525807b1b6e..f7f064e6810c42610bd77bff41a58c6d8784c29e 100644 --- a/graphql/resolvers/annonce.js +++ b/graphql/resolvers/annonce.js @@ -33,5 +33,26 @@ module.exports = { } catch (error) { throw error } - } + }, + + updateAnnonce: async args => { + try { + const annonce = args.annonce; + const idAnnonce = args.idAnnonce; + const annonceModifier = Annonce.findByIdAndUpdate(idAnnonce, annonce, { useFindAndModify: false }); + + return annonceModifier + } catch (error) { + throw error + } + }, + + deleteAnnonce: async args => { + try { + const annonceSupprimee = annonce.deleteAnnonce(args.annonceId); + return "L'annonce " + args.annonceId + " a bien été supprimée"; + } catch (error) { + throw error + } + }, } \ No newline at end of file diff --git a/graphql/schema/annonce.js b/graphql/schema/annonce.js index a8e19eb28ee641bee59b8f03584f9c5ff459ec65..c6f9e4c4102375d1a8d7c970f4ebf98902ac4038 100644 --- a/graphql/schema/annonce.js +++ b/graphql/schema/annonce.js @@ -45,6 +45,17 @@ module.exports = buildSchema(` dateDisponibilite: String! photos: [String] } + + input AnnonceUpdateInput { + titre: String + typeBien: String + statusPublication: String + statusBien: String + description: String + prixBien: Int + dateDisponibilite: String + photos: [String] + } type Query { annonces:[Annonce!] @@ -52,6 +63,8 @@ module.exports = buildSchema(` type Mutation { createAnnonce(annonce: AnnonceInput): String + updateAnnonce(idAnnonce: ID!,annonce:AnnonceUpdateInput): Annonce + deleteAnnonce(annonceId: ID!): String } schema {