refactor(core): Move more typeorm operators to repositories (no-changelog) (#8143)
Follow-up to #8139
This commit is contained in:
@@ -14,6 +14,7 @@ import type { CredentialsEntity } from '@db/entities/CredentialsEntity';
|
||||
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
||||
import { NotFoundError } from '@/errors/response-errors/not-found.error';
|
||||
import { UnauthorizedError } from '@/errors/response-errors/unauthorized.error';
|
||||
import { CredentialsRepository } from '@/databases/repositories/credentials.repository';
|
||||
|
||||
export const EECredentialsController = express.Router();
|
||||
|
||||
@@ -155,10 +156,11 @@ EECredentialsController.put(
|
||||
let newShareeIds: string[] = [];
|
||||
await Db.transaction(async (trx) => {
|
||||
// remove all sharings that are not supposed to exist anymore
|
||||
const { affected } = await EECredentials.pruneSharings(trx, credentialId, [
|
||||
...ownerIds,
|
||||
...shareWithIds,
|
||||
]);
|
||||
const { affected } = await Container.get(CredentialsRepository).pruneSharings(
|
||||
trx,
|
||||
credentialId,
|
||||
[...ownerIds, ...shareWithIds],
|
||||
);
|
||||
if (affected) amountRemoved = affected;
|
||||
|
||||
const sharings = await EECredentials.getSharings(trx, credentialId);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { DeleteResult, EntityManager, FindOptionsWhere } from 'typeorm';
|
||||
import { In, Not } from 'typeorm';
|
||||
import type { EntityManager, FindOptionsWhere } from 'typeorm';
|
||||
import { CredentialsEntity } from '@db/entities/CredentialsEntity';
|
||||
import { SharedCredentials } from '@db/entities/SharedCredentials';
|
||||
import type { SharedCredentials } from '@db/entities/SharedCredentials';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { UserService } from '@/services/user.service';
|
||||
import { CredentialsService, type CredentialsGetSharedOptions } from './credentials.service';
|
||||
@@ -62,18 +61,6 @@ export class EECredentialsService extends CredentialsService {
|
||||
return credential?.shared ?? [];
|
||||
}
|
||||
|
||||
static async pruneSharings(
|
||||
transaction: EntityManager,
|
||||
credentialId: string,
|
||||
userIds: string[],
|
||||
): Promise<DeleteResult> {
|
||||
const conditions: FindOptionsWhere<SharedCredentials> = {
|
||||
credentialsId: credentialId,
|
||||
userId: Not(In(userIds)),
|
||||
};
|
||||
return transaction.delete(SharedCredentials, conditions);
|
||||
}
|
||||
|
||||
static async share(
|
||||
transaction: EntityManager,
|
||||
credential: CredentialsEntity,
|
||||
|
||||
Reference in New Issue
Block a user