WIP - Mass delete working
This commit is contained in:
@@ -694,8 +694,6 @@ export class AiAssistantService {
|
||||
type: field.type,
|
||||
}));
|
||||
|
||||
console.log('fields:',fields);
|
||||
|
||||
const formatInstructions = parser.getFormatInstructions();
|
||||
const today = new Date().toISOString();
|
||||
|
||||
|
||||
@@ -1284,10 +1284,23 @@ export class ObjectService {
|
||||
if (missingIds.length > 0) {
|
||||
throw new NotFoundException(`Records not found: ${missingIds.join(', ')}`);
|
||||
}
|
||||
|
||||
// Check if user can delete each record
|
||||
|
||||
const deletableIds: string[] = [];
|
||||
const deniedIds: string[] = [];
|
||||
|
||||
for (const record of records) {
|
||||
await this.authService.assertCanPerformAction('delete', objectDefModel, record, user, knex);
|
||||
const canDelete = await this.authService.canPerformAction(
|
||||
'delete',
|
||||
objectDefModel,
|
||||
record,
|
||||
user,
|
||||
knex,
|
||||
);
|
||||
if (canDelete) {
|
||||
deletableIds.push(record.id);
|
||||
} else {
|
||||
deniedIds.push(record.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure model is registered
|
||||
@@ -1295,14 +1308,23 @@ export class ObjectService {
|
||||
|
||||
// Use Objection model
|
||||
const boundModel = await this.modelService.getBoundModel(resolvedTenantId, objectApiName);
|
||||
await boundModel.query().whereIn('id', recordIds).delete();
|
||||
if (deletableIds.length > 0) {
|
||||
await boundModel.query().whereIn('id', deletableIds).delete();
|
||||
}
|
||||
|
||||
// Remove from search index
|
||||
await Promise.all(
|
||||
recordIds.map((id) => this.removeIndexedRecord(resolvedTenantId, objectApiName, id)),
|
||||
deletableIds.map((id) =>
|
||||
this.removeIndexedRecord(resolvedTenantId, objectApiName, id),
|
||||
),
|
||||
);
|
||||
|
||||
return { success: true, deleted: recordIds.length };
|
||||
return {
|
||||
success: true,
|
||||
deleted: deletableIds.length,
|
||||
deletedIds: deletableIds,
|
||||
deniedIds,
|
||||
};
|
||||
}
|
||||
|
||||
private async indexRecord(
|
||||
|
||||
Reference in New Issue
Block a user