Skip to content

Commit

Permalink
feat(id): update id properties with index
Browse files Browse the repository at this point in the history
  • Loading branch information
xutyxd committed Sep 29, 2024
1 parent 982c0c0 commit 9f2e8a7
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 53 deletions.
5 changes: 2 additions & 3 deletions src/openapi/folder/examples/folder.example.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
10 changes: 5 additions & 5 deletions src/openapi/folder/models/folder.model.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/openapi/folder/models/partial-folder.model.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "object",
"required": [ "name", "description" ],
"properties": {
"parentId": {
"parentIndex": {
"type": "number",
"example": "1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
6 changes: 3 additions & 3 deletions src/server/file/classes/file-api.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/server/file/classes/file-model.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/server/file/classes/file.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +20,7 @@ export class File extends Record implements IFile {
constructor(file: Optional<IFile, IRecord>) {
super(file);

this.ownerId = file.ownerId;
this.ownerIndex = file.ownerIndex;
this.owner = file.owner;
this.name = file.name;
this.description = file.description;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/server/file/interfaces/file-api.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { IFile } from "./file.interface";

export interface IFileAPI extends Omit<IFile, 'id' | 'ownerId' | 'owner' | 'tags' | 'toModel'> { }
export interface IFileAPI extends Omit<IFile, 'id' | 'ownerIndex' | 'owner' | 'tags' | 'toModel'> { }
2 changes: 1 addition & 1 deletion src/server/file/interfaces/file.interface.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/server/folder/classes/folder-model.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
Expand Down
12 changes: 6 additions & 6 deletions src/server/folder/classes/folder.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,9 +25,9 @@ export class Folder extends Record implements IFolder {
constructor(folder: Optional<IFolder, IRecord>) {
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;
Expand All @@ -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: [],
Expand Down
10 changes: 5 additions & 5 deletions src/server/folder/controllers/folder.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 || [],
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/folder/interfaces/folder-api.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { IFolder } from "./folder.interface";

export interface IFolderAPI extends Omit<IFolder, 'id' | 'ownerId' | 'parentId' | 'filesIds' | 'toModel'> { }
export interface IFolderAPI extends Omit<IFolder, 'id' | 'ownerIndex' | 'parentIndex' | 'filesIds' | 'toModel'> { }
4 changes: 2 additions & 2 deletions src/server/folder/interfaces/folder.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/server/folder/services/folder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export class FolderService extends RecordService<typeof Folder, IFolder, IFolder

public async create(data: Omit<IFolder, keyof IRecord>) {
// 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');
}
Expand Down
6 changes: 3 additions & 3 deletions src/server/tag/classes/tag-api.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/server/tag/classes/tag-model.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/server/tag/classes/tag.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +16,7 @@ export class Tag extends Record implements ITag {
constructor(tag: Optional<ITag, IRecord>) {
super(tag);

this.ownerId = tag.ownerId;
this.ownerIndex = tag.ownerIndex;
this.owner = tag.owner;
this.name = tag.name;
this.description = tag.description;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/server/tag/controllers/tag.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/server/tag/interfaces/tag-api.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ITag } from "./tag.interface";

export interface ITagAPI extends Omit<ITag, 'id' | 'ownerId' | 'toModel'> { }
export interface ITagAPI extends Omit<ITag, 'id' | 'ownerIndex' | 'toModel'> { }
2 changes: 1 addition & 1 deletion src/server/tag/interfaces/tag.interface.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
12 changes: 6 additions & 6 deletions tests/units/folder/controllers/folder.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 9f2e8a7

Please sign in to comment.