mirror of https://github.com/nocodb/nocodb
mertmit
1 year ago
11 changed files with 208 additions and 32 deletions
@ -0,0 +1,16 @@ |
|||||||
|
import type { Knex } from 'knex'; |
||||||
|
import { MetaTable } from '~/utils/globals'; |
||||||
|
|
||||||
|
const up = async (knex: Knex) => { |
||||||
|
await knex.schema.alterTable(MetaTable.BASES, (table) => { |
||||||
|
table.boolean('deleted').defaultTo(false); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
const down = async (knex: Knex) => { |
||||||
|
await knex.schema.alterTable(MetaTable.BASES, (table) => { |
||||||
|
table.dropColumn('deleted'); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
export { up, down }; |
@ -0,0 +1,36 @@ |
|||||||
|
import { Controller, Delete, Inject, Param, UseGuards } from '@nestjs/common'; |
||||||
|
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'; |
||||||
|
import { BasesService } from '~/services/bases.service'; |
||||||
|
|
||||||
|
@Controller() |
||||||
|
@UseGuards(GlobalGuard) |
||||||
|
export class BaseDeleteController { |
||||||
|
constructor( |
||||||
|
@Inject('JobsService') private readonly jobsService, |
||||||
|
private readonly basesService: BasesService, |
||||||
|
) {} |
||||||
|
|
||||||
|
@Delete('/api/v1/db/meta/projects/:projectId/bases/:baseId') |
||||||
|
@Acl('baseDelete') |
||||||
|
async baseDelete(@Param('baseId') baseId: string) { |
||||||
|
const jobs = await this.jobsService.jobList(); |
||||||
|
const fnd = jobs.find( |
||||||
|
(j) => j.name === JobTypes.BaseDelete && j.data.baseId === baseId, |
||||||
|
); |
||||||
|
|
||||||
|
if (fnd) { |
||||||
|
NcError.badRequest('There is already a job running to delete this base.'); |
||||||
|
} |
||||||
|
|
||||||
|
await this.basesService.baseSoftDelete({ baseId }); |
||||||
|
|
||||||
|
const job = await this.jobsService.add(JobTypes.BaseDelete, { |
||||||
|
baseId, |
||||||
|
}); |
||||||
|
|
||||||
|
return { id: job.id }; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
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 BaseDeleteProcessor { |
||||||
|
private readonly debugLog = debug('nc:meta-sync:processor'); |
||||||
|
|
||||||
|
constructor(private readonly basesService: BasesService) {} |
||||||
|
|
||||||
|
@Process(JobTypes.BaseDelete) |
||||||
|
async job(job: Job) { |
||||||
|
const { baseId } = job.data; |
||||||
|
|
||||||
|
await this.basesService.baseDelete({ |
||||||
|
baseId, |
||||||
|
}); |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue