|
|
@ -11,15 +11,13 @@ import { |
|
|
|
Request, |
|
|
|
Request, |
|
|
|
UseGuards, |
|
|
|
UseGuards, |
|
|
|
} from '@nestjs/common'; |
|
|
|
} from '@nestjs/common'; |
|
|
|
import { AuthGuard } from '@nestjs/passport'; |
|
|
|
|
|
|
|
import isDocker from 'is-docker'; |
|
|
|
import isDocker from 'is-docker'; |
|
|
|
import { ProjectReqType } from 'nocodb-sdk'; |
|
|
|
import { ProjectReqType } from 'nocodb-sdk'; |
|
|
|
import { GlobalGuard } from '../guards/global/global.guard'; |
|
|
|
import { GlobalGuard } from '../guards/global/global.guard'; |
|
|
|
import { PagedResponseImpl } from '../helpers/PagedResponse'; |
|
|
|
import { PagedResponseImpl } from '../helpers/PagedResponse'; |
|
|
|
import { |
|
|
|
import { |
|
|
|
ExtractProjectIdMiddleware, |
|
|
|
ExtractProjectIdMiddleware, |
|
|
|
UseAclMiddleware, |
|
|
|
Acl, |
|
|
|
UseProjectIdMiddleware, |
|
|
|
|
|
|
|
} from '../middlewares/extract-project-id/extract-project-id.middleware'; |
|
|
|
} from '../middlewares/extract-project-id/extract-project-id.middleware'; |
|
|
|
import Noco from '../Noco'; |
|
|
|
import Noco from '../Noco'; |
|
|
|
import { packageVersion } from '../utils/packageVersion'; |
|
|
|
import { packageVersion } from '../utils/packageVersion'; |
|
|
@ -31,9 +29,7 @@ import type { ProjectType } from 'nocodb-sdk'; |
|
|
|
export class ProjectsController { |
|
|
|
export class ProjectsController { |
|
|
|
constructor(private readonly projectsService: ProjectsService) {} |
|
|
|
constructor(private readonly projectsService: ProjectsService) {} |
|
|
|
|
|
|
|
|
|
|
|
@UseAclMiddleware({ |
|
|
|
@Acl('projectList') |
|
|
|
permissionName: 'projectList', |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
@Get('/api/v1/db/meta/projects/') |
|
|
|
@Get('/api/v1/db/meta/projects/') |
|
|
|
async list(@Query() queryParams: Record<string, any>, @Request() req) { |
|
|
|
async list(@Query() queryParams: Record<string, any>, @Request() req) { |
|
|
|
const projects = await this.projectsService.projectList({ |
|
|
|
const projects = await this.projectsService.projectList({ |
|
|
@ -57,7 +53,7 @@ export class ProjectsController { |
|
|
|
PackageVersion: packageVersion, |
|
|
|
PackageVersion: packageVersion, |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Acl('projectGet') |
|
|
|
@Get('/api/v1/db/meta/projects/:projectId') |
|
|
|
@Get('/api/v1/db/meta/projects/:projectId') |
|
|
|
async projectGet(@Param('projectId') projectId: string) { |
|
|
|
async projectGet(@Param('projectId') projectId: string) { |
|
|
|
const project = await this.projectsService.getProjectWithInfo({ |
|
|
|
const project = await this.projectsService.getProjectWithInfo({ |
|
|
@ -68,7 +64,7 @@ export class ProjectsController { |
|
|
|
|
|
|
|
|
|
|
|
return project; |
|
|
|
return project; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Acl('projectUpdate') |
|
|
|
@Patch('/api/v1/db/meta/projects/:projectId') |
|
|
|
@Patch('/api/v1/db/meta/projects/:projectId') |
|
|
|
async projectUpdate( |
|
|
|
async projectUpdate( |
|
|
|
@Param('projectId') projectId: string, |
|
|
|
@Param('projectId') projectId: string, |
|
|
@ -82,6 +78,7 @@ export class ProjectsController { |
|
|
|
return project; |
|
|
|
return project; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Acl('projectDelete') |
|
|
|
@Delete('/api/v1/db/meta/projects/:projectId') |
|
|
|
@Delete('/api/v1/db/meta/projects/:projectId') |
|
|
|
async projectDelete(@Param('projectId') projectId: string) { |
|
|
|
async projectDelete(@Param('projectId') projectId: string) { |
|
|
|
const deleted = await this.projectsService.projectSoftDelete({ |
|
|
|
const deleted = await this.projectsService.projectSoftDelete({ |
|
|
@ -91,6 +88,7 @@ export class ProjectsController { |
|
|
|
return deleted; |
|
|
|
return deleted; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Acl('projectCreate') |
|
|
|
@Post('/api/v1/db/meta/projects') |
|
|
|
@Post('/api/v1/db/meta/projects') |
|
|
|
@HttpCode(200) |
|
|
|
@HttpCode(200) |
|
|
|
async projectCreate(@Body() projectBody: ProjectReqType, @Request() req) { |
|
|
|
async projectCreate(@Body() projectBody: ProjectReqType, @Request() req) { |
|
|
@ -102,66 +100,3 @@ export class ProjectsController { |
|
|
|
return project; |
|
|
|
return project; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
// // Project CRUD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function projectCost(req, res) { |
|
|
|
|
|
|
|
let cost = 0; |
|
|
|
|
|
|
|
const project = await Project.getWithInfo(req.params.projectId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const base of project.bases) { |
|
|
|
|
|
|
|
const sqlClient = await NcConnectionMgrv2.getSqlClient(base); |
|
|
|
|
|
|
|
const userCount = await ProjectUser.getUsersCount(req.query); |
|
|
|
|
|
|
|
const recordCount = (await sqlClient.totalRecords())?.data.TotalRecords; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (recordCount > 100000) { |
|
|
|
|
|
|
|
// 36,000 or $79/user/month
|
|
|
|
|
|
|
|
cost = Math.max(36000, 948 * userCount); |
|
|
|
|
|
|
|
} else if (recordCount > 50000) { |
|
|
|
|
|
|
|
// $36,000 or $50/user/month
|
|
|
|
|
|
|
|
cost = Math.max(36000, 600 * userCount); |
|
|
|
|
|
|
|
} else if (recordCount > 10000) { |
|
|
|
|
|
|
|
// $240/user/yr
|
|
|
|
|
|
|
|
cost = Math.min(240 * userCount, 36000); |
|
|
|
|
|
|
|
} else if (recordCount > 1000) { |
|
|
|
|
|
|
|
// $120/user/yr
|
|
|
|
|
|
|
|
cost = Math.min(120 * userCount, 36000); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
T.event({ |
|
|
|
|
|
|
|
event: 'a:project:cost', |
|
|
|
|
|
|
|
data: { |
|
|
|
|
|
|
|
cost, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.json({ cost }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function hasEmptyOrNullFilters(req, res) { |
|
|
|
|
|
|
|
res.json(await Filter.hasEmptyOrNullFilters(req.params.projectId)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default (router) => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router.get( |
|
|
|
|
|
|
|
'/api/v1/db/meta/projects/:projectId/cost', |
|
|
|
|
|
|
|
metaApiMetrics, |
|
|
|
|
|
|
|
ncMetaAclMw(projectCost, 'projectCost') |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router.get( |
|
|
|
|
|
|
|
'/api/v1/db/meta/projects/:projectId/has-empty-or-null-filters', |
|
|
|
|
|
|
|
metaApiMetrics, |
|
|
|
|
|
|
|
ncMetaAclMw(hasEmptyOrNullFilters, 'hasEmptyOrNullFilters') |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* */ |
|
|
|
|
|
|
|