Uploading the Repo
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
const { v4 } = require("uuid");
|
||||
const { animals } = require("../db");
|
||||
const Mutation = {
|
||||
addAnimal: (
|
||||
parent,
|
||||
{ image, title, rating, price, description, slug, stock, onSale, category },
|
||||
{ animals }
|
||||
) => {
|
||||
let newAnimal = {
|
||||
id: v4(),
|
||||
image,
|
||||
title,
|
||||
rating,
|
||||
price,
|
||||
description,
|
||||
slug,
|
||||
stock,
|
||||
onSale,
|
||||
category,
|
||||
};
|
||||
animals.push(newAnimal);
|
||||
return newAnimal;
|
||||
},
|
||||
removeAnimal: (parent, { id }, { animals }) => {
|
||||
let index = animals.findIndex((animal) => {
|
||||
return animal.id === id;
|
||||
});
|
||||
animals.splice(index, 1);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = { Mutation };
|
||||
Reference in New Issue
Block a user