feat: add meta field to project entity and corresponding migration, service, and controller updates
This commit is contained in:
15
src/migrations/1760548310371-projectmeta.ts
Normal file
15
src/migrations/1760548310371-projectmeta.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class Projectmeta1760548310371 implements MigrationInterface {
|
||||||
|
name = "Projectmeta1760548310371";
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`project\` ADD \`meta\` longtext NULL`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE \`project\` DROP COLUMN \`meta\``);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/project/constants.ts
Normal file
11
src/project/constants.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
type item = {
|
||||||
|
id: string;
|
||||||
|
path: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TMeta = {
|
||||||
|
migrations: item[];
|
||||||
|
queries: item[];
|
||||||
|
functions: item[];
|
||||||
|
settings: item[];
|
||||||
|
};
|
||||||
@ -15,6 +15,7 @@ import { FunctionEntity } from "../../query/entities/function.entity";
|
|||||||
import { RedisNode } from "../../redisManager/entities/redis.node.entity";
|
import { RedisNode } from "../../redisManager/entities/redis.node.entity";
|
||||||
import { Log } from "../../query/logger/entities/log.entity";
|
import { Log } from "../../query/logger/entities/log.entity";
|
||||||
import { ProjectSetting } from "../settings/entities/project.setting.entity";
|
import { ProjectSetting } from "../settings/entities/project.setting.entity";
|
||||||
|
import { TMeta } from "../constants";
|
||||||
|
|
||||||
@Entity("project")
|
@Entity("project")
|
||||||
export class Project {
|
export class Project {
|
||||||
@ -43,6 +44,16 @@ export class Project {
|
|||||||
@OneToMany(() => ProjectSetting, (setting) => setting.project)
|
@OneToMany(() => ProjectSetting, (setting) => setting.project)
|
||||||
settings: ProjectSetting[];
|
settings: ProjectSetting[];
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
type: "longtext",
|
||||||
|
nullable: true,
|
||||||
|
transformer: {
|
||||||
|
to: (value: TMeta) => JSON.stringify(value),
|
||||||
|
from: (value: string) => JSON.parse(value) as TMeta,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
meta: TMeta;
|
||||||
|
|
||||||
@ManyToMany(() => RedisNode, (redisNode) => redisNode.projects)
|
@ManyToMany(() => RedisNode, (redisNode) => redisNode.projects)
|
||||||
@JoinTable()
|
@JoinTable()
|
||||||
redisNodes: RedisNode[];
|
redisNodes: RedisNode[];
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import {
|
|||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
Inject,
|
Inject,
|
||||||
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Req,
|
Req,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
@ -13,6 +14,7 @@ import { ApiTokenGuard } from "src/api/guards/api-token.guard";
|
|||||||
import { AdminGuard } from "src/api/guards/admin.guard";
|
import { AdminGuard } from "src/api/guards/admin.guard";
|
||||||
import { Request } from "express";
|
import { Request } from "express";
|
||||||
import { ProjectSettingService } from "./settings/project.setting.service";
|
import { ProjectSettingService } from "./settings/project.setting.service";
|
||||||
|
import { TMeta } from "./constants";
|
||||||
|
|
||||||
@Controller("project")
|
@Controller("project")
|
||||||
@UseGuards(ApiTokenGuard)
|
@UseGuards(ApiTokenGuard)
|
||||||
@ -36,6 +38,14 @@ export class ProjectController {
|
|||||||
return this.projectService.getProjectDetails(req.apiToken.project.id);
|
return this.projectService.getProjectDetails(req.apiToken.project.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post("update/meta")
|
||||||
|
updateProjectMeta(
|
||||||
|
@Body() body: { meta: TMeta },
|
||||||
|
@Req() req: Request & { apiToken: { project: { id: string } } }
|
||||||
|
) {
|
||||||
|
return this.projectService.updateMeta(req.apiToken.project.id, body.meta);
|
||||||
|
}
|
||||||
|
|
||||||
@Put("create-without-db")
|
@Put("create-without-db")
|
||||||
@UseGuards(AdminGuard)
|
@UseGuards(AdminGuard)
|
||||||
createProjectWithoutDB(@Body() body: { name: string }) {
|
createProjectWithoutDB(@Body() body: { name: string }) {
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { Project } from "./entities/project.entity";
|
|||||||
import { RedisClient } from "src/redis/redis.service";
|
import { RedisClient } from "src/redis/redis.service";
|
||||||
import { DatabaseManagerService } from "src/databaseManager/database/database.manager.service";
|
import { DatabaseManagerService } from "src/databaseManager/database/database.manager.service";
|
||||||
import { ProjectSettingService } from "./settings/project.setting.service";
|
import { ProjectSettingService } from "./settings/project.setting.service";
|
||||||
|
import { TMeta } from "./constants";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ProjectService {
|
export class ProjectService {
|
||||||
@ -45,16 +46,30 @@ export class ProjectService {
|
|||||||
return projectSaved;
|
return projectSaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateMeta(projectId: string, meta: TMeta) {
|
||||||
|
return this.projectRepository.update({ id: projectId }, { meta });
|
||||||
|
}
|
||||||
|
|
||||||
async getProjectDetails(projectId: string) {
|
async getProjectDetails(projectId: string) {
|
||||||
const project = await this.projectRepository.findOne({
|
const project = await this.projectRepository.findOne({
|
||||||
where: { id: projectId },
|
where: { id: projectId },
|
||||||
relations: ["database", "database.migrations", "queries", "functions"],
|
relations: [
|
||||||
|
"database",
|
||||||
|
"database.migrations",
|
||||||
|
"queries",
|
||||||
|
"functions",
|
||||||
|
"settings",
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
migrations: project?.database?.migrations || [],
|
migrations: project?.database?.migrations || [],
|
||||||
queries: project?.queries || [],
|
queries: project?.queries || [],
|
||||||
functions: project?.functions || [],
|
functions: project?.functions || [],
|
||||||
|
settings: project?.settings || [],
|
||||||
|
meta: project?.meta || null,
|
||||||
|
name: project?.name || "",
|
||||||
|
id: project?.id || "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +104,7 @@ export class ProjectService {
|
|||||||
redisNodes: redisNodeId,
|
redisNodes: redisNodeId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllApiTokens(projectId: string) {
|
async getAllApiTokens(projectId: string) {
|
||||||
const project = await this.projectRepository.findOne({
|
const project = await this.projectRepository.findOne({
|
||||||
where: { id: projectId },
|
where: { id: projectId },
|
||||||
|
|||||||
Reference in New Issue
Block a user