From 588835adbe9bb95710b3b6aa3b68b3530f3d4898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BB=8Bnh=20Duy=20H=C6=B0ng?= <57101685+HUNG-rushb@users.noreply.github.com> Date: Fri, 15 Dec 2023 16:53:33 +0700 Subject: [PATCH] ok --- src/Type_Definitions/Album_Album.js | 4 ++-- src/resolvers/Mutation/album.js | 33 ++++++++++++++++------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Type_Definitions/Album_Album.js b/src/Type_Definitions/Album_Album.js index 3220c35..60a7586 100644 --- a/src/Type_Definitions/Album_Album.js +++ b/src/Type_Definitions/Album_Album.js @@ -29,7 +29,7 @@ const albumDefs = gql` deleteAlbum(data: DeleteAlbumInput!): Album! deleteAllAlbum: DeleteAllReturnType! - updateAlbum(data: UpdateAlbumInput!): Album! + addNewPhotoToAlbum(data: UpdateAlbumInput!): Album! } input CreateAlbumInput { @@ -43,7 +43,7 @@ const albumDefs = gql` input UpdateAlbumInput { albumId: ID! - name: String! + postIds: [ID]! } type Album { diff --git a/src/resolvers/Mutation/album.js b/src/resolvers/Mutation/album.js index 733fdaa..86b852c 100644 --- a/src/resolvers/Mutation/album.js +++ b/src/resolvers/Mutation/album.js @@ -44,24 +44,27 @@ const albumMutation = { return result; }, //!!!!!!!!!!!!!!!!!!!!!!!!!!!! - updateAlbum: async (parent, args, info) => { - const { updatedUser, ...updateInfo } = args.data; - let result; - try { - updatedUser = await prisma.user.update({ - where: { - id: userId, + addNewPhotoToAlbum: async (parent, args, info) => { + const { albumId, postIds } = args.data; + + await prisma.post.updateMany({ + where: { + id: { + in: postIds, }, - data: { - ...updateInfo, + }, + data: { + albumId: { + push: albumId, }, - }); - } catch (e) { - console.log(e); - throw e; - } + }, + }); - return updatedUser; + return await prisma.album.findUnique({ + where: { + id: albumId, + }, + }); }, };