diff --git a/src/openapi/folder/examples/folder.example.json b/src/openapi/folder/examples/folder.example.json index 63b11ed..66ad46b 100644 --- a/src/openapi/folder/examples/folder.example.json +++ b/src/openapi/folder/examples/folder.example.json @@ -1,12 +1,11 @@ { "code": 200, "data": { - "id": 1, "uuid": "c0a8433f-d6b1-4f38-a94a-2c9a0d0c1c4d", "createdAt": 1679022000000, "updatedAt": 1679022000000, - "ownerId": 1, - "parentId": 1, + "ownerIndex": "947fc5bb-7cca-47d0-9432-f5a716bc7b3b", + "parentIndex": "f0a6f400-be55-42ae-9545-1bcba9b69b99", "name": "Folder name", "description": "Folder description" }, diff --git a/src/openapi/folder/models/folder.model.json b/src/openapi/folder/models/folder.model.json index 47934a1..0a694ed 100644 --- a/src/openapi/folder/models/folder.model.json +++ b/src/openapi/folder/models/folder.model.json @@ -1,6 +1,6 @@ { "type": "object", - "required": [ "id", "uuid", "createdAt", "updatedAt", "ownerId", "parentId", "name", "description" ], + "required": [ "id", "uuid", "createdAt", "updatedAt", "ownerIndex", "parentIndex", "name", "description" ], "properties": { "id": { "type": "number", @@ -18,13 +18,13 @@ "type": "number", "example": "1679022000000" }, - "ownerId": { + "ownerIndex": { "type": "number", - "example": "1" + "example": "947fc5bb-7cca-47d0-9432-f5a716bc7b3b" }, - "parentId": { + "parentIndex": { "type": "number", - "example": "1" + "example": "f0a6f400-be55-42ae-9545-1bcba9b69b99" }, "name": { "type": "string", diff --git a/src/openapi/folder/models/partial-folder.model.json b/src/openapi/folder/models/partial-folder.model.json index 128758b..8425e78 100644 --- a/src/openapi/folder/models/partial-folder.model.json +++ b/src/openapi/folder/models/partial-folder.model.json @@ -2,7 +2,7 @@ "type": "object", "required": [ "name", "description" ], "properties": { - "parentId": { + "parentIndex": { "type": "number", "example": "1" }, diff --git a/src/package/index.ts b/src/package/index.ts index 188877d..d30ef43 100644 --- a/src/package/index.ts +++ b/src/package/index.ts @@ -37,7 +37,7 @@ export class PhotronAPIClient { } public folders = { - create: async (data: { name: string, description: string, parentId?: number }) => { + create: async (data: { name: string, description: string, parentIndex?: number }) => { return this.client.POST('/folders', { body: data }); }, list: async () => { diff --git a/src/server/file/classes/file-api.class.ts b/src/server/file/classes/file-api.class.ts index 5433828..dd9c44d 100644 --- a/src/server/file/classes/file-api.class.ts +++ b/src/server/file/classes/file-api.class.ts @@ -4,7 +4,7 @@ import { IFile } from "../interfaces/file.interface"; export class FileAPI extends RecordAPI implements IFileAPI { - public ownerId: string; + public ownerIndex: string; public owner: string; public name: string; public description?: string; @@ -16,7 +16,7 @@ export class FileAPI extends RecordAPI implements IFileAPI { constructor(file: IFile) { super(file); - this.ownerId = file.ownerId; + this.ownerIndex = file.ownerIndex; this.owner = file.owner; this.name = file.name; this.description = file.description; @@ -29,7 +29,7 @@ export class FileAPI extends RecordAPI implements IFileAPI { public export() { return { ...super.export(), - ownerId: this.ownerId, + ownerIndex: this.ownerIndex, owner: this.owner, name: this.name, description: this.description, diff --git a/src/server/file/classes/file-model.class.ts b/src/server/file/classes/file-model.class.ts index 7e79c63..94ac963 100644 --- a/src/server/file/classes/file-model.class.ts +++ b/src/server/file/classes/file-model.class.ts @@ -16,7 +16,7 @@ export class FileModel extends RecordModel implements IFileModel { constructor(file: IFile) { super(file); - this.owner_id = file.ownerId; + this.owner_id = file.ownerIndex; this.owner = file.owner; this.name = file.name; this.description = file.description; diff --git a/src/server/file/classes/file.class.ts b/src/server/file/classes/file.class.ts index 9507c47..289a856 100644 --- a/src/server/file/classes/file.class.ts +++ b/src/server/file/classes/file.class.ts @@ -7,7 +7,7 @@ import { FileModel } from "./file-model.class"; export class File extends Record implements IFile { - public ownerId: string; + public ownerIndex: string; public name: string; public description?: string; public size: number; @@ -20,7 +20,7 @@ export class File extends Record implements IFile { constructor(file: Optional) { super(file); - this.ownerId = file.ownerId; + this.ownerIndex = file.ownerIndex; this.owner = file.owner; this.name = file.name; this.description = file.description; @@ -40,7 +40,7 @@ export class File extends Record implements IFile { uuid: file.uuid, createdAt: file.created_at, updatedAt: file.updated_at, - ownerId: file.owner_id, + ownerIndex: file.owner_id, owner: file.owner, name: file.name, description: file.description, diff --git a/src/server/file/interfaces/file-api.interface.ts b/src/server/file/interfaces/file-api.interface.ts index b7b43ed..d04494a 100644 --- a/src/server/file/interfaces/file-api.interface.ts +++ b/src/server/file/interfaces/file-api.interface.ts @@ -1,3 +1,3 @@ import { IFile } from "./file.interface"; -export interface IFileAPI extends Omit { } \ No newline at end of file +export interface IFileAPI extends Omit { } \ No newline at end of file diff --git a/src/server/file/interfaces/file.interface.ts b/src/server/file/interfaces/file.interface.ts index 4c321e3..d6c763c 100644 --- a/src/server/file/interfaces/file.interface.ts +++ b/src/server/file/interfaces/file.interface.ts @@ -1,7 +1,7 @@ import { IRecord } from "../../crosscutting/common/interfaces/record.interface"; export interface IFile extends IRecord { - ownerId: string; + ownerIndex: string; owner: string; name: string; description?: string; diff --git a/src/server/folder/classes/folder-model.class.ts b/src/server/folder/classes/folder-model.class.ts index 1928043..24a09cb 100644 --- a/src/server/folder/classes/folder-model.class.ts +++ b/src/server/folder/classes/folder-model.class.ts @@ -26,9 +26,9 @@ export class FolderModel extends RecordModel implements IFolderModel { constructor(folder: IFolder) { super(folder); - this.owner_id = folder.ownerId; + this.owner_id = folder.ownerIndex; this.owner = folder.owner; - this.parent_id = folder.parentId; + this.parent_id = folder.parentIndex; this.parent = folder.parent; this.name = folder.name || ''; this.description = folder.description || ''; diff --git a/src/server/folder/classes/folder.class.ts b/src/server/folder/classes/folder.class.ts index b6fd875..368b210 100644 --- a/src/server/folder/classes/folder.class.ts +++ b/src/server/folder/classes/folder.class.ts @@ -9,8 +9,8 @@ import { FolderModel } from "./folder-model.class"; export class Folder extends Record implements IFolder { - public ownerId: string; - public parentId?: string; + public ownerIndex: string; + public parentIndex?: string; public name: string; public description?: string; @@ -25,9 +25,9 @@ export class Folder extends Record implements IFolder { constructor(folder: Optional) { super(folder); - this.ownerId = folder.ownerId; + this.ownerIndex = folder.ownerIndex; this.owner = folder.owner; - this.parentId = folder.parentId; + this.parentIndex = folder.parentIndex; this.parent = folder.parent; this.files = (folder.files || []).map((file) => new File(file)); this.name = folder.name; @@ -44,8 +44,8 @@ export class Folder extends Record implements IFolder { uuid: folder.uuid, createdAt: folder.created_at, updatedAt: folder.updated_at, - ownerId: folder.owner_id, - parentId: folder.parent_id, + ownerIndex: folder.owner_id, + parentIndex: folder.parent_id, name: folder.name, description: folder.description, files: [], diff --git a/src/server/folder/controllers/folder.controller.ts b/src/server/folder/controllers/folder.controller.ts index f5d4b11..4525310 100644 --- a/src/server/folder/controllers/folder.controller.ts +++ b/src/server/folder/controllers/folder.controller.ts @@ -38,7 +38,7 @@ export class FolderController implements IHTTPController { public async create(request: HTTPRequest, context: IHTTPContextData) { - const { name, description, parentId, tags = { include: [], exclude: [] } } = request.body; + const { name, description, parentIndex, tags = { include: [], exclude: [] } } = request.body; if (!name) { throw new BadRequestResponse('Property "name" is required', context); @@ -50,8 +50,8 @@ export class FolderController implements IHTTPController { const folder = await this.folderService.create({ name, description, - parentId, - ownerId: context.user.sub, + parentIndex, + ownerIndex: context.user.sub, files: [], tags: { include: tags.include || [], @@ -116,7 +116,7 @@ export class FolderController implements IHTTPController { public async update(request: HTTPRequest, context: IHTTPContextData) { const { uuid } = request.params; - const { name, description, parentId } = request.body; + const { name, description, parentIndex } = request.body; if (!uuid) { throw new BadRequestResponse('Property "uuid" is required', context); @@ -125,7 +125,7 @@ export class FolderController implements IHTTPController { let result: IFolderAPI ; try { - const folder = await this.folderService.update(uuid, { name, description, parentId }); + const folder = await this.folderService.update(uuid, { name, description, parentIndex }); result = new FolderAPI({ ...folder, owner: context.user.name }).export(); } catch (error) { diff --git a/src/server/folder/interfaces/folder-api.interface.ts b/src/server/folder/interfaces/folder-api.interface.ts index 16b2ad9..47d7e81 100644 --- a/src/server/folder/interfaces/folder-api.interface.ts +++ b/src/server/folder/interfaces/folder-api.interface.ts @@ -1,3 +1,3 @@ import { IFolder } from "./folder.interface"; -export interface IFolderAPI extends Omit { } \ No newline at end of file +export interface IFolderAPI extends Omit { } \ No newline at end of file diff --git a/src/server/folder/interfaces/folder.interface.ts b/src/server/folder/interfaces/folder.interface.ts index 92fa8a2..05d3d09 100644 --- a/src/server/folder/interfaces/folder.interface.ts +++ b/src/server/folder/interfaces/folder.interface.ts @@ -3,9 +3,9 @@ import { IFile } from "../../file/interfaces/file.interface"; import { ITag } from "../../tag/interfaces/tag.interface"; export interface IFolder extends IRecord { - ownerId: string; + ownerIndex: string; owner?: string; - parentId?: string; + parentIndex?: string; parent?: string; name: string; description?: string; diff --git a/src/server/folder/services/folder.service.ts b/src/server/folder/services/folder.service.ts index b92446c..f4cc022 100644 --- a/src/server/folder/services/folder.service.ts +++ b/src/server/folder/services/folder.service.ts @@ -16,9 +16,9 @@ export class FolderService extends RecordService) { // Check if the parent folder exists - if (data.parentId) { + if (data.parentIndex) { try { - await this.get(data.parentId); + await this.get(data.parentIndex); } catch (error) { throw new InternalError('Parent folder not found'); } diff --git a/src/server/tag/classes/tag-api.class.ts b/src/server/tag/classes/tag-api.class.ts index f5d0141..f69c459 100644 --- a/src/server/tag/classes/tag-api.class.ts +++ b/src/server/tag/classes/tag-api.class.ts @@ -4,7 +4,7 @@ import { ITag } from "../interfaces/tag.interface"; export class TagAPI extends RecordAPI implements ITagAPI { - public ownerId: string; + public ownerIndex: string; public owner?: string; public name: string; public description?: string; @@ -13,7 +13,7 @@ export class TagAPI extends RecordAPI implements ITagAPI { constructor(tag: ITag) { super(tag); - this.ownerId = tag.ownerId; + this.ownerIndex = tag.ownerIndex; this.owner = tag.owner; this.name = tag.name; this.description = tag.description; @@ -23,7 +23,7 @@ export class TagAPI extends RecordAPI implements ITagAPI { public export() { return { ...super.export(), - ownerId: this.ownerId, + ownerIndex: this.ownerIndex, owner: this.owner, name: this.name, description: this.description, diff --git a/src/server/tag/classes/tag-model.class.ts b/src/server/tag/classes/tag-model.class.ts index f49eb1b..7a11f43 100644 --- a/src/server/tag/classes/tag-model.class.ts +++ b/src/server/tag/classes/tag-model.class.ts @@ -13,7 +13,7 @@ export class TagModel extends RecordModel implements ITagModel { constructor(tag: ITag) { super(tag); - this.owner_id = tag.ownerId; + this.owner_id = tag.ownerIndex; this.owner = tag.owner; this.name = tag.name; this.description = tag.description; diff --git a/src/server/tag/classes/tag.class.ts b/src/server/tag/classes/tag.class.ts index 8f1ca8a..5fda830 100644 --- a/src/server/tag/classes/tag.class.ts +++ b/src/server/tag/classes/tag.class.ts @@ -7,7 +7,7 @@ import { TagModel } from "./tag-model.class"; export class Tag extends Record implements ITag { - public ownerId: string; + public ownerIndex: string; public owner?: string; public name: string; public description?: string; @@ -16,7 +16,7 @@ export class Tag extends Record implements ITag { constructor(tag: Optional) { super(tag); - this.ownerId = tag.ownerId; + this.ownerIndex = tag.ownerIndex; this.owner = tag.owner; this.name = tag.name; this.description = tag.description; @@ -33,7 +33,7 @@ export class Tag extends Record implements ITag { uuid: tag.uuid, createdAt: tag.created_at, updatedAt: tag.updated_at, - ownerId: tag.owner_id, + ownerIndex: tag.owner_id, owner: tag.owner, name: tag.name, description: tag.description, diff --git a/src/server/tag/controllers/tag.controller.ts b/src/server/tag/controllers/tag.controller.ts index a98e773..1487f3b 100644 --- a/src/server/tag/controllers/tag.controller.ts +++ b/src/server/tag/controllers/tag.controller.ts @@ -50,7 +50,7 @@ export class TagController implements IHTTPController { name, description, color, - ownerId: context.user.sub + ownerIndex: context.user.sub }); result = new TagAPI(tag).export(); diff --git a/src/server/tag/interfaces/tag-api.interface.ts b/src/server/tag/interfaces/tag-api.interface.ts index a25f74a..7354741 100644 --- a/src/server/tag/interfaces/tag-api.interface.ts +++ b/src/server/tag/interfaces/tag-api.interface.ts @@ -1,3 +1,3 @@ import { ITag } from "./tag.interface"; -export interface ITagAPI extends Omit { } \ No newline at end of file +export interface ITagAPI extends Omit { } \ No newline at end of file diff --git a/src/server/tag/interfaces/tag.interface.ts b/src/server/tag/interfaces/tag.interface.ts index 7ded95e..5fce4d0 100644 --- a/src/server/tag/interfaces/tag.interface.ts +++ b/src/server/tag/interfaces/tag.interface.ts @@ -1,7 +1,7 @@ import { IRecord } from "../../crosscutting/common/interfaces/record.interface"; export interface ITag extends IRecord { - ownerId: string; + ownerIndex: string; owner?: string; name: string; description?: string; diff --git a/tests/units/folder/controllers/folder.controller.spec.ts b/tests/units/folder/controllers/folder.controller.spec.ts index 43a0330..9b18b12 100644 --- a/tests/units/folder/controllers/folder.controller.spec.ts +++ b/tests/units/folder/controllers/folder.controller.spec.ts @@ -66,7 +66,7 @@ describe('FolderController', () => { let response: IFolderAPI | InternalErrorResponse; try { - response = await controller.create({ body: { name: 'test', description: 'test', parentId: 1, ownerId: 1 } } as any, { user: { sub: 1234 } } as any); + response = await controller.create({ body: { name: 'test', description: 'test', parentIndex: 1, ownerIndex: 1 } } as any, { user: { sub: 1234 } } as any); } catch (e) { response = e as InternalErrorResponse; } @@ -80,7 +80,7 @@ describe('FolderController', () => { it('should create a folder without parent', async () => { - const body = { name: 'test', description: 'test', ownerId: 1 }; + const body = { name: 'test', description: 'test', ownerIndex: 1 }; const request = { body } as any; const context = { user: { sub: 1234, name: '1234-test' } } as any; @@ -104,7 +104,7 @@ describe('FolderController', () => { }); it('should create a folder and return it', async () => { - const body = { name: 'test', description: 'test', ownerId: 1 }; + const body = { name: 'test', description: 'test', ownerIndex: 1 }; const request = { body } as any; const context = { user: { sub: 1234, name: '1234-test' } } as any; @@ -154,7 +154,7 @@ describe('FolderController', () => { }); it('should get a folder', async () => { - const body = { name: 'test', description: 'test', ownerId: 1 }; + const body = { name: 'test', description: 'test', ownerIndex: 1 }; const request = { body } as any; const context = { user: { sub: 1234, name: '1234-test' } } as any; @@ -206,7 +206,7 @@ describe('FolderController', () => { }); it('should update a folder', async () => { - const body = { name: 'test', description: 'test', ownerId: 1 }; + const body = { name: 'test', description: 'test', ownerIndex: 1 }; const request = { body } as any; const context = { user: { sub: 1234, name: '1234-test' } } as any; @@ -256,7 +256,7 @@ describe('FolderController', () => { }); it('should delete a folder', async () => { - const body = { name: 'test', description: 'test', ownerId: 1 }; + const body = { name: 'test', description: 'test', ownerIndex: 1 }; const request = { body } as any; const context = { user: { sub: 1234, name: '1234-test' } } as any;