n8n/packages/cli/src/databases/repositories/sharedCredentials.repository.ts
कारतोफ्फेलस्क्रिप्ट™ 464b565283
ci: Remove unnecessary async/await, enable await-thenable linting rule (no-changelog) (#8076)
## Summary
We accidentally made some functions `async` in
https://github.com/n8n-io/n8n/pull/7846
This PR reverts that change. 

## Review / Merge checklist
- [x] PR title and summary are descriptive.
2023-12-19 13:52:42 +01:00

25 lines
787 B
TypeScript

import { Service } from 'typedi';
import { DataSource, Repository } from 'typeorm';
import { SharedCredentials } from '../entities/SharedCredentials';
import type { User } from '../entities/User';
@Service()
export class SharedCredentialsRepository extends Repository<SharedCredentials> {
constructor(dataSource: DataSource) {
super(SharedCredentials, dataSource.manager);
}
/** Get a credential if it has been shared with a user */
async findCredentialForUser(credentialsId: string, user: User) {
const sharedCredential = await this.findOne({
relations: ['credentials'],
where: {
credentialsId,
...(!user.hasGlobalScope('credential:read') ? { userId: user.id } : {}),
},
});
if (!sharedCredential) return null;
return sharedCredential.credentials;
}
}