REFACTOR: Project Pattern and AuthClient (DUC)

This commit is contained in:
Victor Radael
2022-03-14 10:35:03 -03:00
parent 2f8d9b9550
commit 363bc8b350
163 changed files with 2544 additions and 4138 deletions
+23
View File
@@ -0,0 +1,23 @@
import { credentials } from '@grpc/grpc-js';
import { ClientOptions, Transport } from '@nestjs/microservices';
import { DucProtofile } from '@victorradael/protospack';
export class AuthClient {
config(): ClientOptions {
return {
transport: Transport.GRPC,
options: {
url: process.env.DUC_URL,
package: 'duc',
credentials: credentials.createSsl(),
protoPath: DucProtofile,
loader: {
enums: String,
objects: true,
arrays: true,
},
},
};
}
}
+43
View File
@@ -0,0 +1,43 @@
import { OnModuleInit, Inject } from '@nestjs/common';
import { ClientGrpc } from '@nestjs/microservices';
import { CognitoServiceInterface } from '@victorradael/protospack';
import { ILogin } from './interfaces';
export class AuthClientService implements OnModuleInit {
private cognitoService: CognitoServiceInterface;
constructor(
@Inject('AUTH_PACKAGE') private readonly grpcClient: ClientGrpc,
) {}
onModuleInit() {
this.cognitoService = this.grpcClient.getService<CognitoServiceInterface>(
'CognitoProtoService',
);
}
async signIn({ username, password }: ILogin): Promise<any> {
console.log('CognitoClientService', 'SignIn');
const tokens = await new Promise((resolve, reject) => {
this.cognitoService.signIn({ username, password }).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return tokens;
}
}
+4
View File
@@ -0,0 +1,4 @@
export interface ILogin {
username: string;
password: string;
}