Compare commits
3 Commits
develop
...
projectDet
| Author | SHA1 | Date | |
|---|---|---|---|
| ee5ad66759 | |||
| f7b775f87b | |||
| 6992041429 |
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 { Log } from "../../query/logger/entities/log.entity";
|
||||
import { ProjectSetting } from "../settings/entities/project.setting.entity";
|
||||
import { TMeta } from "../constants";
|
||||
|
||||
@Entity("project")
|
||||
export class Project {
|
||||
@ -43,6 +44,16 @@ export class Project {
|
||||
@OneToMany(() => ProjectSetting, (setting) => setting.project)
|
||||
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)
|
||||
@JoinTable()
|
||||
redisNodes: RedisNode[];
|
||||
|
||||
@ -4,6 +4,7 @@ import {
|
||||
Delete,
|
||||
Get,
|
||||
Inject,
|
||||
Post,
|
||||
Put,
|
||||
Req,
|
||||
UseGuards,
|
||||
@ -11,7 +12,9 @@ import {
|
||||
import { ProjectService } from "./project.service";
|
||||
import { ApiTokenGuard } from "src/api/guards/api-token.guard";
|
||||
import { AdminGuard } from "src/api/guards/admin.guard";
|
||||
import { Request } from "express";
|
||||
import { ProjectSettingService } from "./settings/project.setting.service";
|
||||
import { TMeta } from "./constants";
|
||||
|
||||
@Controller("project")
|
||||
@UseGuards(ApiTokenGuard)
|
||||
@ -28,6 +31,21 @@ export class ProjectController {
|
||||
return this.projectService.create(body.name);
|
||||
}
|
||||
|
||||
@Get("details")
|
||||
getProjectDetails(
|
||||
@Req() req: Request & { apiToken: { project: { id: string } } }
|
||||
) {
|
||||
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")
|
||||
@UseGuards(AdminGuard)
|
||||
createProjectWithoutDB(@Body() body: { name: string }) {
|
||||
@ -63,6 +81,5 @@ export class ProjectController {
|
||||
@UseGuards(AdminGuard)
|
||||
getAllApiTokens(@Req() req: Request & { apiToken: { id: string } }) {
|
||||
return this.projectService.getAllApiTokens(req.apiToken.id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import { Project } from "./entities/project.entity";
|
||||
import { RedisClient } from "src/redis/redis.service";
|
||||
import { DatabaseManagerService } from "src/databaseManager/database/database.manager.service";
|
||||
import { ProjectSettingService } from "./settings/project.setting.service";
|
||||
import { TMeta } from "./constants";
|
||||
|
||||
@Injectable()
|
||||
export class ProjectService {
|
||||
@ -45,6 +46,33 @@ export class ProjectService {
|
||||
return projectSaved;
|
||||
}
|
||||
|
||||
async updateMeta(projectId: string, meta: TMeta) {
|
||||
return this.projectRepository.update({ id: projectId }, { meta });
|
||||
}
|
||||
|
||||
async getProjectDetails(projectId: string) {
|
||||
const project = await this.projectRepository.findOne({
|
||||
where: { id: projectId },
|
||||
relations: [
|
||||
"database",
|
||||
"database.migrations",
|
||||
"queries",
|
||||
"functions",
|
||||
"settings",
|
||||
],
|
||||
});
|
||||
|
||||
return {
|
||||
migrations: project?.database?.migrations || [],
|
||||
queries: project?.queries || [],
|
||||
functions: project?.functions || [],
|
||||
settings: project?.settings || [],
|
||||
meta: project?.meta || null,
|
||||
name: project?.name || "",
|
||||
id: project?.id || "",
|
||||
};
|
||||
}
|
||||
|
||||
async findById(id: string) {
|
||||
const cached = await this.redisClient.get(`project_${id}`);
|
||||
|
||||
@ -76,7 +104,7 @@ export class ProjectService {
|
||||
redisNodes: redisNodeId,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async getAllApiTokens(projectId: string) {
|
||||
const project = await this.projectRepository.findOne({
|
||||
where: { id: projectId },
|
||||
|
||||
Reference in New Issue
Block a user