-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new methods markCollectionsAsDeleted and markWorkbooksAsDeleted (#…
…197) * Add to registry method markWorkbooksAsDeleted * Add new method for delete workbooks * Add clear permissions * Add new method markCollectionsAsDeleted * Refactor * Add getting patents * Rm * Fix check pemissions * fix
- Loading branch information
1 parent
4d67a31
commit 50743c8
Showing
10 changed files
with
234 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/services/new/collection/utils/mark-collections-as-deleted.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {raw} from 'objection'; | ||
import {CURRENT_TIMESTAMP} from '../../../../const'; | ||
import {ServiceArgs} from '../../types'; | ||
import {getPrimary} from '../../utils'; | ||
import {CollectionModel, CollectionModelColumn} from '../../../../db/models/new/collection'; | ||
import {CollectionInstance} from '../../../../registry/common/entities/collection/types'; | ||
|
||
export const markCollectionsAsDeleted = async ( | ||
{ctx, trx, skipCheckPermissions}: ServiceArgs, | ||
{collectionsMap}: {collectionsMap: Map<CollectionInstance, string[]>}, | ||
) => { | ||
const collectionIds: string[] = []; | ||
|
||
collectionsMap.forEach((parentIds, collectionInstance) => { | ||
collectionIds.push(collectionInstance.model.collectionId); | ||
}); | ||
|
||
const { | ||
user: {userId}, | ||
} = ctx.get('info'); | ||
|
||
const deletedCollections = await CollectionModel.query(getPrimary(trx)) | ||
.patch({ | ||
[CollectionModelColumn.DeletedBy]: userId, | ||
[CollectionModelColumn.DeletedAt]: raw(CURRENT_TIMESTAMP), | ||
}) | ||
.where(CollectionModelColumn.CollectionId, 'in', collectionIds) | ||
.andWhere({ | ||
[CollectionModelColumn.DeletedAt]: null, | ||
}) | ||
.returning('*') | ||
.timeout(CollectionModel.DEFAULT_QUERY_TIMEOUT); | ||
|
||
const deletePermissionsPromises: Promise<void>[] = []; | ||
|
||
collectionsMap.forEach((parentIds, collectionInstance) => { | ||
deletePermissionsPromises.push( | ||
collectionInstance.deletePermissions({ | ||
parentIds, | ||
skipCheckPermissions, | ||
}), | ||
); | ||
}); | ||
|
||
await Promise.all(deletePermissionsPromises); | ||
|
||
return deletedCollections; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.