-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
import type { AuthContext, AuthUser } from '../../types/user'; | ||
import { type BasicStoreEntityDeleteOperation, ENTITY_TYPE_DELETE_OPERATION } from './deleteOperation-types'; | ||
import { FunctionalError } from '../../config/errors'; | ||
import { elDeleteInstances, elFindByIds } from '../../database/engine'; | ||
import { deleteAllObjectFiles } from '../../database/file-storage'; | ||
import { listEntitiesPaginated, storeLoadById } from '../../database/middleware-loader'; | ||
import { READ_INDEX_DELETED_OBJECTS } from '../../database/utils'; | ||
import type { QueryDeleteOperationsArgs } from '../../generated/graphql'; | ||
import { type BasicStoreEntityDeleteOperation, ENTITY_TYPE_DELETE_OPERATION } from './deleteOperation-types'; | ||
|
||
export interface DeletedElement { | ||
id: string | ||
source_index: string | ||
} | ||
import type { AuthContext, AuthUser } from '../../types/user'; | ||
|
||
export const findById = (context: AuthContext, user: AuthUser, id: string) => { | ||
export const findById = async (context: AuthContext, user: AuthUser, id: string) => { | ||
return storeLoadById<BasicStoreEntityDeleteOperation>(context, user, id, ENTITY_TYPE_DELETE_OPERATION); | ||
}; | ||
Check warning on line 12 in opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-domain.ts
|
||
|
||
export const findAll = (context: AuthContext, user: AuthUser, args: QueryDeleteOperationsArgs) => { | ||
export const findAll = async (context: AuthContext, user: AuthUser, args: QueryDeleteOperationsArgs) => { | ||
return listEntitiesPaginated<BasicStoreEntityDeleteOperation>(context, user, [ENTITY_TYPE_DELETE_OPERATION], args); | ||
}; | ||
Check warning on line 16 in opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-domain.ts
|
||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const restoreDelete = (context: AuthContext, user: AuthUser, id: string) => { | ||
export const restoreDelete = async (context: AuthContext, user: AuthUser, id: string) => { | ||
throw new Error('Restore delete not implemented'); | ||
}; | ||
Check warning on line 21 in opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-domain.ts
|
||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const completeDelete = (context: AuthContext, user: AuthUser, id: string) => { | ||
throw new Error('Complete delete not implemented'); | ||
export const completeDelete = async (context: AuthContext, user: AuthUser, id: string) => { | ||
const deleteOperation = await findById(context, user, id); | ||
if (!deleteOperation) { | ||
throw FunctionalError(`Delete operation ${id} cannot be found`); | ||
} | ||
const deletedElementsIds = deleteOperation.deleted_elements.map((el) => el.id); | ||
// get deleted elements (from deleted_objects index) | ||
const deletedElements: any[] = await elFindByIds(context, user, deletedElementsIds, { indices: READ_INDEX_DELETED_OBJECTS }) as any[]; | ||
for (let index = 0; index < deletedElements.length; index += 1) { | ||
const element = deletedElements[index]; | ||
// delete files | ||
await deleteAllObjectFiles(context, user, element); | ||
} | ||
// delete elements & delete operation | ||
await elDeleteInstances([...deletedElements]); | ||
await elDeleteInstances([deleteOperation]); | ||
return id; | ||
}; | ||
Check warning on line 40 in opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-domain.ts
|