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: Docs: CRUD #23

Merged
merged 2 commits into from
Oct 7, 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
14 changes: 14 additions & 0 deletions prisma/migrations/20231007154157_item_docs/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- CreateTable
CREATE TABLE "ItemDocs" (
"id" SERIAL NOT NULL,
"text" TEXT NOT NULL,
"itemId" INTEGER NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "ItemDocs_itemId_key" ON "ItemDocs"("itemId");

-- AddForeignKey
ALTER TABLE "ItemDocs" ADD CONSTRAINT "ItemDocs_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "Item"("id") ON DELETE CASCADE ON UPDATE CASCADE;
15 changes: 12 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ model Item {
Items Item[] @relation("ItemToItem")
ItemFolder ItemFolder?
ItemBlob ItemBlob?
ItemDocs ItemDocs?
ItemSharing ItemSharing[]

createdAt DateTime @default(now())
Expand All @@ -66,9 +67,9 @@ model Item {
}

model ItemFolder {
id Int @id @default(autoincrement())
color String @db.VarChar(255)
itemId Int @unique
id Int @id @default(autoincrement())
color String @db.VarChar(255)
itemId Int @unique

item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
}
Expand All @@ -81,6 +82,14 @@ model ItemBlob {
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
}

model ItemDocs {
id Int @id @default(autoincrement())
text String @db.Text
itemId Int @unique

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

model ItemSharing {
id Int @id @default(autoincrement())
itemId Int
Expand Down
20 changes: 20 additions & 0 deletions src/locales/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
"folder": {
"notFound": "Mappen blev ikke fundet"
},
"docs": {
"notFound": "Dokumentet blev ikke fundet"
},
"notFound": "Item ikke fundet"
},
"folder": {
Expand All @@ -123,5 +126,22 @@
"parentId": {
"type": "Parent id skal være et tal"
}
},
"docs": {
"id": {
"required": "id er påkrævet",
"type": "id skal være et tal"
},
"name": {
"required": "Navn er påkrævet",
"type": "Navn skal være en tekst"
},
"text": {
"required": "Tekst er påkrævet",
"type": "Tekst skal være en tekst"
},
"parentId": {
"type": "Parent id skal være et tal"
}
}
}
20 changes: 20 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
"folder": {
"notFound": "Folder not found"
},
"docs": {
"notFound": "Docs not found"
},
"notFound": "Item not found"
},
"folder": {
Expand All @@ -123,5 +126,22 @@
"parentId": {
"type": "Parent id must be a number"
}
},
"docs": {
"id": {
"required": "id is required",
"type": "id must be a number"
},
"name": {
"required": "Name is required",
"type": "Name must be a string"
},
"text": {
"required": "Text is required",
"type": "Text must be a string"
},
"parentId": {
"type": "Parent id must be a number"
}
}
}
21 changes: 21 additions & 0 deletions src/modules/item/__test__/item.read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import UserService from '../../auth/user.service';
import FolderService from '../folder/folder.service';
import AuthService from '../../auth/auth.service';
import BlobService from '../blob/blob.service';
import DocsService from '../docs/docs.service';

describe('GET /api/item/:parentId', () => {
let userService: UserService;
let folderService: FolderService;
let authService: AuthService;
let blobService: BlobService;
let docsService: DocsService;

let user: User;
let otherUser: User;
Expand All @@ -18,6 +20,7 @@ describe('GET /api/item/:parentId', () => {
folderService = new FolderService();
authService = new AuthService();
blobService = new BlobService();
docsService = new DocsService();

user = await userService.createUser({
name: 'Joe Biden the 1st',
Expand Down Expand Up @@ -56,6 +59,13 @@ describe('GET /api/item/:parentId', () => {
parentId: parentFolder.id,
});

await docsService.createDocs({
name: 'Docs1',
text: 'Docs1 text',
ownerId: user.id,
parentId: parentFolder.id,
});

const response = await global.fastify.inject({
method: 'GET',
url: '/api/item/' + parentFolder.id,
Expand Down Expand Up @@ -88,6 +98,17 @@ describe('GET /api/item/:parentId', () => {
deletedAt: null,
updatedAt: expect.any(String),
},
{
id: expect.any(Number),
name: 'Docs1',
text: 'Docs1 text',
parentId: parentFolder.id,
ownerId: user.id,
mimeType: 'application/vnd.cloudstore.docs',
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
},
]);
});

Expand Down
21 changes: 21 additions & 0 deletions src/modules/item/__test__/item.root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import UserService from '../../auth/user.service';
import FolderService from '../folder/folder.service';
import AuthService from '../../auth/auth.service';
import BlobService from '../blob/blob.service';
import DocsService from '../docs/docs.service';

describe('GET /api/item', () => {
let userService: UserService;
let folderService: FolderService;
let authService: AuthService;
let blobService: BlobService;
let docsService: DocsService;

let user: User;

Expand All @@ -17,6 +19,7 @@ describe('GET /api/item', () => {
folderService = new FolderService();
authService = new AuthService();
blobService = new BlobService();
docsService = new DocsService();

user = await userService.createUser({
name: 'Joe Biden the 1st',
Expand Down Expand Up @@ -49,6 +52,13 @@ describe('GET /api/item', () => {
parentId: null,
});

await docsService.createDocs({
name: 'Docs1',
text: 'Docs1 text',
ownerId: user.id,
parentId: null,
});

const response = await global.fastify.inject({
method: 'GET',
url: '/api/item',
Expand Down Expand Up @@ -92,6 +102,17 @@ describe('GET /api/item', () => {
deletedAt: null,
updatedAt: expect.any(String),
},
{
id: expect.any(Number),
name: 'Docs1',
text: 'Docs1 text',
parentId: null,
ownerId: user.id,
mimeType: 'application/vnd.cloudstore.docs',
createdAt: expect.any(String),
deletedAt: null,
updatedAt: expect.any(String),
},
]);
});

Expand Down
Loading