Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added starred endpoints #26

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions prisma/migrations/20231011083919_item_starred/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- CreateTable
CREATE TABLE "ItemStarred" (
"id" SERIAL NOT NULL,
"itemId" INTEGER NOT NULL,
"userId" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "ItemStarred_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "ItemStarred_itemId_idx" ON "ItemStarred"("itemId");

-- CreateIndex
CREATE INDEX "ItemStarred_userId_idx" ON "ItemStarred"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "ItemStarred_itemId_userId_key" ON "ItemStarred"("itemId", "userId");

-- AddForeignKey
ALTER TABLE "ItemStarred" ADD CONSTRAINT "ItemStarred_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "Item"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ItemStarred" ADD CONSTRAINT "ItemStarred_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
18 changes: 18 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ model User {
sessions UserSession[]
Item Item[]
ItemSharing ItemSharing[]
ItemStarred ItemStarred[]

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down Expand Up @@ -57,6 +58,7 @@ model Item {
ItemSharing ItemSharing[]
ItemShortcut ItemShortcut? @relation("shortcutItem")
LinkedItemShortcut ItemShortcut[] @relation("linkedItem")
ItemStarred ItemStarred[]

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down Expand Up @@ -118,3 +120,19 @@ model ItemShortcut {

@@index([linkedItemId])
}

model ItemStarred {
id Int @id @default(autoincrement())
itemId Int
userId Int

item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

Anders164a marked this conversation as resolved.
Show resolved Hide resolved
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@unique([itemId, userId])
@@index([itemId])
@@index([userId])
}
18 changes: 18 additions & 0 deletions src/locales/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
"shortcut": {
"notFound": "Genvej blev ikke fundet"
},
"starred": {
"notFound": "Stjernemarkeringen blev ikke fundet",
"alreadyExists": "Stjernemarkeringen findes allerede"
},
"notFound": "Item ikke fundet"
},
"folder": {
Expand Down Expand Up @@ -163,5 +167,19 @@
"parentId": {
"type": "Parent id skal være et tal"
}
},
"starred": {
"id": {
"required": "id er påkrævet",
"type": "id skal være et tal"
},
"userId": {
"required": "userId er påkrævet",
"type": "userId skal være et tal"
},
"itemId": {
"required": "itemId er påkrævet",
"type": "itemId skal være et tal"
}
}
}
18 changes: 18 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
"shortcut": {
"notFound": "Shortcut not found"
},
"starred": {
"notFound": "Starred not found",
"alreadyExists": "Starred already exists"
},
"notFound": "Item not found"
},
"folder": {
Expand Down Expand Up @@ -163,5 +167,19 @@
"parentId": {
"type": "Parent id must be a number"
}
},
"starred": {
"id": {
"required": "id is required",
"type": "id must be a number"
},
"userId": {
"required": "userId is required",
"type": "userId must be a number"
},
"itemId": {
"required": "itemId is required",
"type": "itemId must be a number"
}
}
}
4 changes: 4 additions & 0 deletions src/modules/item/__test__/item.read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('GET /api/item/:parentId', () => {
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -107,6 +108,7 @@ describe('GET /api/item/:parentId', () => {
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -118,6 +120,7 @@ describe('GET /api/item/:parentId', () => {
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -128,6 +131,7 @@ describe('GET /api/item/:parentId', () => {
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
isStarred: false,
},
]);
});
Expand Down
5 changes: 5 additions & 0 deletions src/modules/item/__test__/item.root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe('GET /api/item', () => {
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -100,6 +101,7 @@ describe('GET /api/item', () => {
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -111,6 +113,7 @@ describe('GET /api/item', () => {
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -122,6 +125,7 @@ describe('GET /api/item', () => {
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -132,6 +136,7 @@ describe('GET /api/item', () => {
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
isStarred: false,
},
]);
});
Expand Down
15 changes: 15 additions & 0 deletions src/modules/item/__test__/item.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -94,6 +95,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -106,6 +108,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -118,6 +121,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
]);
});
Expand Down Expand Up @@ -247,6 +251,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -259,6 +264,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -271,6 +277,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -283,6 +290,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -295,6 +303,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -307,6 +316,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -319,6 +329,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
];
const expectedSharredUser = [
Expand All @@ -333,6 +344,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -345,6 +357,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -357,6 +370,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
{
id: expect.any(Number),
Expand All @@ -369,6 +383,7 @@ describe('ItemService', () => {
createdAt: expect.any(Date),
deletedAt: null,
updatedAt: expect.any(Date),
isStarred: false,
},
];

Expand Down
Loading