feat: complete day 11

This commit is contained in:
Ayobami
2025-07-17 16:55:13 +01:00
parent 001e4b6d00
commit 9c84737fed
18 changed files with 919 additions and 177 deletions
+63
View File
@@ -0,0 +1,63 @@
const db = require("../../models");
const ActorResolvers = {
Query: {
async getActor(_, { id }) {
try {
const actor = await db.actor.findByPk(id, {
include: [
{ model: db.movie, as: "movies", through: { attributes: [] } },
],
});
if (!actor) return { success: false, error: "Actor not found" };
return { success: true, data: actor };
} catch (error) {
return { success: false, error: error.message };
}
},
async getAllActors() {
try {
const actors = await db.actor.findAll({
include: [
{ model: db.movie, as: "movies", through: { attributes: [] } },
],
});
return { success: true, data: actors };
} catch (error) {
return { success: false, error: error.message };
}
},
},
Mutation: {
async createActor(_, args) {
try {
const actor = await db.actor.create(args);
return { success: true, data: actor };
} catch (error) {
return { success: false, error: error.message };
}
},
async updateActor(_, { id, ...args }) {
try {
const actor = await db.actor.findByPk(id);
if (!actor) return { success: false, error: "Actor not found" };
await actor.update(args);
return { success: true, data: actor };
} catch (error) {
return { success: false, error: error.message };
}
},
async deleteActor(_, { id }) {
try {
const actor = await db.actor.findByPk(id);
if (!actor) return { success: false, error: "Actor not found" };
await actor.destroy();
return { success: true, data: actor };
} catch (error) {
return { success: false, error: error.message };
}
},
},
};
module.exports = ActorResolvers;