mirror of https://github.com/nocodb/nocodb
mertmit
1 year ago
7 changed files with 91 additions and 22 deletions
@ -0,0 +1,46 @@
|
||||
import { |
||||
Body, |
||||
Controller, |
||||
HttpCode, |
||||
Inject, |
||||
Param, |
||||
Post, |
||||
UseGuards, |
||||
} from '@nestjs/common'; |
||||
import { BaseReqType } from 'nocodb-sdk'; |
||||
import { GlobalGuard } from '~/guards/global/global.guard'; |
||||
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware'; |
||||
import { NcError } from '~/helpers/catchError'; |
||||
import { JobTypes } from '~/interface/Jobs'; |
||||
|
||||
@Controller() |
||||
@UseGuards(GlobalGuard) |
||||
export class BaseCreateController { |
||||
constructor(@Inject('JobsService') private readonly jobsService) {} |
||||
|
||||
@Post('/api/v1/db/meta/projects/:projectId/bases') |
||||
@HttpCode(200) |
||||
@Acl('baseCreate') |
||||
async baseCreate( |
||||
@Param('projectId') projectId: string, |
||||
@Body() body: BaseReqType, |
||||
) { |
||||
const jobs = await this.jobsService.jobList(); |
||||
const fnd = jobs.find( |
||||
(j) => j.name === JobTypes.BaseCreate && j.data.projectId === projectId, |
||||
); |
||||
|
||||
if (fnd) { |
||||
NcError.badRequest( |
||||
'Another base creation is in progress for this project.', |
||||
); |
||||
} |
||||
|
||||
const job = await this.jobsService.add(JobTypes.BaseCreate, { |
||||
projectId, |
||||
base: body, |
||||
}); |
||||
|
||||
return { id: job.id }; |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
import debug from 'debug'; |
||||
import { Process, Processor } from '@nestjs/bull'; |
||||
import { Job } from 'bull'; |
||||
import { JOBS_QUEUE, JobTypes } from '~/interface/Jobs'; |
||||
import { BasesService } from '~/services/bases.service'; |
||||
|
||||
@Processor(JOBS_QUEUE) |
||||
export class BaseCreateProcessor { |
||||
private readonly debugLog = debug('nc:meta-sync:processor'); |
||||
|
||||
constructor(private readonly basesService: BasesService) {} |
||||
|
||||
@Process(JobTypes.BaseCreate) |
||||
async job(job: Job) { |
||||
const { projectId, base } = job.data; |
||||
|
||||
const createdBase = await this.basesService.baseCreate({ |
||||
projectId, |
||||
base, |
||||
}); |
||||
|
||||
if (createdBase.isMeta()) { |
||||
delete createdBase.config; |
||||
} |
||||
|
||||
return createdBase; |
||||
} |
||||
} |
Loading…
Reference in new issue