feat: add auth server package

This commit is contained in:
Karol Sójko
2022-06-22 12:33:00 +02:00
parent 143b215ddc
commit 8e5012009b
684 changed files with 33080 additions and 172 deletions
@@ -0,0 +1,57 @@
import { inject, injectable } from 'inversify'
import { Repository } from 'typeorm'
import TYPES from '../../Bootstrap/Types'
import { InvitationStatus } from '../../Domain/SharedSubscription/InvitationStatus'
import { SharedSubscriptionInvitation } from '../../Domain/SharedSubscription/SharedSubscriptionInvitation'
import { SharedSubscriptionInvitationRepositoryInterface } from '../../Domain/SharedSubscription/SharedSubscriptionInvitationRepositoryInterface'
@injectable()
export class MySQLSharedSubscriptionInvitationRepository implements SharedSubscriptionInvitationRepositoryInterface {
constructor(
@inject(TYPES.ORMSharedSubscriptionInvitationRepository)
private ormRepository: Repository<SharedSubscriptionInvitation>,
) {}
async save(sharedSubscriptionInvitation: SharedSubscriptionInvitation): Promise<SharedSubscriptionInvitation> {
return this.ormRepository.save(sharedSubscriptionInvitation)
}
async findByInviterEmail(inviterEmail: string): Promise<SharedSubscriptionInvitation[]> {
return this.ormRepository
.createQueryBuilder('invitation')
.where('invitation.inviter_identifier = :inviterEmail', {
inviterEmail,
})
.getMany()
}
async countByInviterEmailAndStatus(inviterEmail: string, statuses: InvitationStatus[]): Promise<number> {
return this.ormRepository
.createQueryBuilder('invitation')
.where('invitation.inviter_identifier = :inviterEmail AND invitation.status IN (:...statuses)', {
inviterEmail,
statuses,
})
.getCount()
}
async findOneByUuid(uuid: string): Promise<SharedSubscriptionInvitation | null> {
return this.ormRepository
.createQueryBuilder('invitation')
.where('invitation.uuid = :uuid', {
uuid,
})
.getOne()
}
async findOneByUuidAndStatus(uuid: string, status: InvitationStatus): Promise<SharedSubscriptionInvitation | null> {
return this.ormRepository
.createQueryBuilder('invitation')
.where('invitation.uuid = :uuid AND invitation.status = :status', {
uuid,
status,
})
.getOne()
}
}