-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bde4a1
commit 1a53b3d
Showing
6 changed files
with
155 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[id,organizerId]` on the table `Feast` will be added. If there are existing duplicate values, this will fail. | ||
- A unique constraint covering the columns `[id,shepherdId]` on the table `Herd` will be added. If there are existing duplicate values, this will fail. | ||
- A unique constraint covering the columns `[id,feastId,googleId]` on the table `Place` will be added. If there are existing duplicate values, this will fail. | ||
- A unique constraint covering the columns `[id,userId,placeId]` on the table `Vote` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Feast_id_organizerId_key" ON "Feast"("id", "organizerId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Herd_id_shepherdId_key" ON "Herd"("id", "shepherdId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Place_id_feastId_googleId_key" ON "Place"("id", "feastId", "googleId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Vote_id_userId_placeId_key" ON "Vote"("id", "userId", "placeId"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import prisma from '../db' | ||
|
||
// Get all herds | ||
export const getAllHerds = async (req, res) => { | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
id: req.user.id, | ||
}, | ||
include: { | ||
herds: true, | ||
}, | ||
}) | ||
|
||
res.json({ ok: true, herds: user.herds }) | ||
} | ||
|
||
// Get created herds | ||
export const getShepHerds = async (req, res) => { | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
id: req.user.id, | ||
}, | ||
include: { | ||
shepHerds: true, | ||
}, | ||
}) | ||
|
||
res.json({ ok: true, data: { shepHerds: user.shepHerds } }) | ||
} | ||
|
||
// Get one herd | ||
export const getHerd = async (req, res) => { | ||
const id = req.params.id | ||
const herd = await prisma.herd.findFirst({ | ||
where: { | ||
id, | ||
members: { | ||
some: { | ||
id: req.user.id, | ||
}, | ||
}, | ||
}, | ||
}) | ||
res.json({ ok: true, data: { herd } }) | ||
} | ||
|
||
// Create a herd | ||
export const createHerd = async (req, res) => { | ||
const herd = await prisma.herd.create({ | ||
data: { | ||
name: req.body.name, | ||
shepherdId: req.user.id, | ||
}, | ||
}) | ||
res.json({ ok: true, data: { herd } }) | ||
} | ||
|
||
// Update a herd | ||
export const updateHerd = async (req, res) => { | ||
const updated = await prisma.herd.update({ | ||
where: { | ||
id_shepherdId: { | ||
id: req.params.id, | ||
shepherdId: req.user.id, | ||
}, | ||
}, | ||
data: req.body, | ||
}) | ||
res.json({ ok: true, data: { updated } }) | ||
} | ||
|
||
// Delete a herd | ||
export const deleteHerd = async (req, res) => { | ||
const deleted = await prisma.herd.delete({ | ||
where: { | ||
id_shepherdId: { | ||
id: req.params.id, | ||
shepherdId: req.user.id, | ||
}, | ||
}, | ||
}) | ||
res.json({ ok: true, data: { deleted } }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters