feat(api): add auth guards
This commit is contained in:
1 parent
3a86676a12
commit
d4b790fd86
16 files changed
+592
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
||||
import { ConnectionService } from '../global/database/connection.service';
|
||||
import { IdentityDocument } from '../global/database/schema';
|
||||
|
||||
interface IdentityInput {
|
||||
entraOid: string;
|
||||
tenantId?: string;
|
||||
email?: string;
|
||||
displayName?: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class IdentityService {
|
||||
constructor(private readonly connectionService: ConnectionService) {}
|
||||
|
||||
public async findOrCreateByOid(
|
||||
input: IdentityInput,
|
||||
): Promise<IdentityDocument> {
|
||||
const IdentityModel = await this.connectionService.getModel('identity');
|
||||
const identity = await IdentityModel.findOneAndUpdate(
|
||||
{ entraOid: input.entraOid },
|
||||
{
|
||||
$set: {
|
||||
tenantId: input.tenantId,
|
||||
email: input.email,
|
||||
displayName: input.displayName,
|
||||
lastSignInAt: new Date(),
|
||||
},
|
||||
$setOnInsert: { entraOid: input.entraOid },
|
||||
},
|
||||
{ upsert: true, returnDocument: 'after', setDefaultsOnInsert: true },
|
||||
).exec();
|
||||
|
||||
if (!identity) {
|
||||
throw new InternalServerErrorException('Failed to resolve identity.');
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user