import { v4 as uuidv4 } from 'uuid';
import * as db from './database.js';
export const resolvers = {
Query: {
adlEntries: () => {
return db.getAllEntries();
},
adlEntry: (_, { id }) => {
return db.getEntryById(id);
},
searchADLEntries: (_, { search }) => {
return db.searchEntries(search);
}
},
Mutation: {
createADLEntry: (_, { input }) => {
const now = new Date().toISOString();
const entry = {
id: uuidv4(),
created: now,
lastEdited: now,
...input
};
return db.createEntry(entry);
},
updateADLEntry: (_, { id, input }) => {
const updated = db.updateEntry(id, input);
if (!updated) {
throw new Error(`ADL entry with id ${id} not found`);
}
return updated;
},
deleteADLEntry: (_, { id }) => {
const success = db.deleteEntry(id);
if (!success) {
throw new Error(`ADL entry with id ${id} not found`);
}
return success;
}
}
};