Skip to content

Commit

Permalink
#22 - Make Item endpoint work with ItemDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianbinau committed Oct 7, 2023
1 parent 22cebc5 commit e43ebcb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
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
10 changes: 8 additions & 2 deletions src/modules/item/item.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import {
Item as prismaItemType,
ItemBlob as prismaItemBlobType,
ItemFolder as prismaItemFolderType,
ItemDocs as prismaItemDocsType,
} from '@prisma/client';
import { FromSchema } from 'json-schema-to-ts';

export type Item = prismaItemType;

export type ItemPrismaProperties = Item & { ItemBlob: prismaItemBlobType | null } & {
ItemFolder: prismaItemFolderType | null;
};
} & { ItemDocs: prismaItemDocsType | null };

export type ItemWithProperties = Item &
Omit<Partial<prismaItemBlobType>, 'id' | 'itemId'> &
Omit<Partial<prismaItemFolderType>, 'id' | 'itemId'>;
Omit<Partial<prismaItemFolderType>, 'id' | 'itemId'> &
Omit<Partial<prismaItemDocsType>, 'id' | 'itemId'>;

export type CreateItem = Omit<Item, 'id' | 'createdAt' | 'updatedAt' | 'deletedAt'>;

Expand Down Expand Up @@ -52,6 +55,9 @@ const itemsResponseSchema = {
color: {
type: ['string', 'null'],
},
text: {
type: ['string', 'null'],
},
blobUrl: {
type: ['string', 'null'],
},
Expand Down
5 changes: 4 additions & 1 deletion src/modules/item/item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class ItemService {
include: {
ItemBlob: true,
ItemFolder: true,
ItemDocs: true,
},
});

Expand Down Expand Up @@ -70,6 +71,7 @@ export default class ItemService {
include: {
ItemBlob: true,
ItemFolder: true,
ItemDocs: true,
},
});

Expand All @@ -78,11 +80,12 @@ export default class ItemService {

private formatItems(items: ItemPrismaProperties[]): ItemWithProperties[] {
return items.map((element) => {
const { ItemFolder, ItemBlob, ...strippedElement } = element;
const { ItemFolder, ItemBlob, ItemDocs, ...strippedElement } = element;

return {
...ItemBlob,
...ItemFolder,
...ItemDocs,
...strippedElement,
};
});
Expand Down

0 comments on commit e43ebcb

Please sign in to comment.