modified template for auth
This commit is contained in:
parent
da0d495894
commit
fcb8b6e428
40
package-lock.json
generated
40
package-lock.json
generated
@ -21,6 +21,7 @@
|
||||
"axios": "^1.10.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.1",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"jwk-to-pem": "^2.0.7",
|
||||
"mssql": "^10.0.4",
|
||||
@ -42,6 +43,7 @@
|
||||
"@nestjs/testing": "^11.0.1",
|
||||
"@swc/cli": "^0.6.0",
|
||||
"@swc/core": "^1.10.7",
|
||||
"@types/cookie-parser": "^1.4.9",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/jwk-to-pem": "^2.0.3",
|
||||
@ -3798,6 +3800,16 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/cookie-parser": {
|
||||
"version": "1.4.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/cookie-parser/-/cookie-parser-1.4.9.tgz",
|
||||
"integrity": "sha512-tGZiZ2Gtc4m3wIdLkZ8mkj1T6CEHb35+VApbL2T14Dew8HA7c+04dmKqsKRNC+8RJPm16JEK0tFSwdZqubfc4g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"@types/express": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/cookiejar": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.5.tgz",
|
||||
@ -6205,6 +6217,34 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie-parser": {
|
||||
"version": "1.4.7",
|
||||
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.7.tgz",
|
||||
"integrity": "sha512-nGUvgXnotP3BsjiLX2ypbQnWoGUPIIfHQNZkkC668ntrzGWEZVW70HDEB1qnNGMicPje6EttlIgzo51YSwNQGw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cookie": "0.7.2",
|
||||
"cookie-signature": "1.0.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie-parser/node_modules/cookie": {
|
||||
"version": "0.7.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
||||
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie-parser/node_modules/cookie-signature": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/cookie-signature": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz",
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
"axios": "^1.10.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.1",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"jwk-to-pem": "^2.0.7",
|
||||
"mssql": "^10.0.4",
|
||||
@ -53,6 +54,7 @@
|
||||
"@nestjs/testing": "^11.0.1",
|
||||
"@swc/cli": "^0.6.0",
|
||||
"@swc/core": "^1.10.7",
|
||||
"@types/cookie-parser": "^1.4.9",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/jwk-to-pem": "^2.0.3",
|
||||
|
||||
@ -90,4 +90,11 @@ export class AuthController {
|
||||
|
||||
return { statusCode: 200, message: "Tokens refreshed successfully" }
|
||||
}
|
||||
|
||||
// @Get('checkRoles')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
// @Roles('ca')
|
||||
roleChecking() {
|
||||
return { message: "role checking successfull..." }
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,10 +14,46 @@ import { ConflictException } from 'src/exceptions/conflict.exception';
|
||||
export class AuthService {
|
||||
private keyCache: Record<string, string> = {};
|
||||
|
||||
private readonly KEYCLOAK_URL: string;
|
||||
private readonly KEYCLOAK_REALM: string;
|
||||
private readonly KEYCLOAK_BASE_URL: string;
|
||||
private readonly JWKS_URL: string;
|
||||
private readonly TOKENS_INTROSPECT_URL: string;
|
||||
private readonly CLIENT_ID: string;
|
||||
private readonly CLIENT_SECRET: string;
|
||||
private readonly TOKEN_URL: string;
|
||||
private readonly USERS_URL: string;
|
||||
|
||||
constructor(
|
||||
private readonly oracleDBService: OracleDBService,
|
||||
private readonly configService: ConfigService,
|
||||
) { }
|
||||
) {
|
||||
const KEYCLOAK_URL = this.configService.get<string>('KEYCLOAK_URL');
|
||||
if (!KEYCLOAK_URL) throw new Error('Environment variable KEYCLOAK_URL is not set');
|
||||
this.KEYCLOAK_URL = KEYCLOAK_URL;
|
||||
|
||||
const KEYCLOAK_REALM = this.configService.get<string>('KEYCLOAK_REALM');
|
||||
if (!KEYCLOAK_REALM) throw new Error('Environment variable KEYCLOAK_REALM is not set');
|
||||
this.KEYCLOAK_REALM = KEYCLOAK_REALM;
|
||||
|
||||
const CLIENT_ID = this.configService.get<string>('CLIENT_ID');
|
||||
if (!CLIENT_ID) throw new Error('Environment variable KEYCLOAK CLIENT_ID is not set');
|
||||
this.CLIENT_ID = CLIENT_ID;
|
||||
|
||||
const CLIENT_SECRET = this.configService.get<string>('CLIENT_SECRET');
|
||||
if (!CLIENT_SECRET) throw new Error('Environment variable KEYCLOAK CLIENT_SECRET is not set');
|
||||
this.CLIENT_SECRET = CLIENT_SECRET;
|
||||
|
||||
this.KEYCLOAK_BASE_URL = `${this.KEYCLOAK_URL}/realms/${this.KEYCLOAK_REALM}/protocol/openid-connect`;
|
||||
|
||||
this.JWKS_URL = `${this.KEYCLOAK_BASE_URL}/certs`
|
||||
|
||||
this.TOKENS_INTROSPECT_URL = `${this.KEYCLOAK_BASE_URL}/token/introspect`
|
||||
|
||||
this.TOKEN_URL = `${this.KEYCLOAK_BASE_URL}/token`
|
||||
|
||||
this.USERS_URL = `${this.KEYCLOAK_URL}/realms/${this.KEYCLOAK_REALM}/users`;
|
||||
}
|
||||
|
||||
async login(body: AuthLoginDTO) {
|
||||
let connection;
|
||||
@ -87,32 +123,23 @@ export class AuthService {
|
||||
|
||||
private async getPublicKey(kid: string): Promise<string> {
|
||||
if (this.keyCache[kid]) return this.keyCache[kid];
|
||||
|
||||
const jwksUri = `${this.configService.get('KEYCLOAK_URL')}/realms/${this.configService.get(
|
||||
'REALM',
|
||||
)}/protocol/openid-connect/certs`;
|
||||
|
||||
const { data } = await axios.get(jwksUri);
|
||||
const { data } = await axios.get(this.JWKS_URL);
|
||||
const key = data.keys.find((k) => k.kid === kid);
|
||||
if (!key) throw new InternalServerErrorException('Key not found');
|
||||
|
||||
const pem = jwkToPem(key);
|
||||
this.keyCache[kid] = pem;
|
||||
return pem;
|
||||
}
|
||||
|
||||
async introspectToken(token: string): Promise<any> {
|
||||
const url = `${this.configService.get('KEYCLOAK_URL')}/realms/${this.configService.get(
|
||||
'REALM',
|
||||
)}/protocol/openid-connect/token/introspect`;
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.append('token', token);
|
||||
params.append('client_id', this.configService.get('CLIENT_ID') || '');
|
||||
params.append('client_secret', this.configService.get('CLIENT_SECRET') || '');
|
||||
params.append('client_id', this.CLIENT_ID);
|
||||
params.append('client_secret', this.CLIENT_SECRET);
|
||||
|
||||
|
||||
const response = await axios.post(url, params, {
|
||||
const response = await axios.post(this.TOKENS_INTROSPECT_URL, params, {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
});
|
||||
|
||||
@ -130,8 +157,6 @@ export class AuthService {
|
||||
|
||||
const introspection = await this.introspectToken(token);
|
||||
|
||||
console.log('introspec : ', introspection);
|
||||
|
||||
if (!introspection.active) {
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
@ -143,11 +168,10 @@ export class AuthService {
|
||||
async getAdminAccessTokenx(): Promise<string> {
|
||||
const data = new URLSearchParams();
|
||||
data.append('grant_type', 'client_credentials');
|
||||
data.append('client_id', this.configService.get('CLIENT_ID') || '');
|
||||
data.append('client_secret', this.configService.get('CLIENT_SECRET') || '');
|
||||
let KEYCLOAK_URL = await this.configService.get('KEYCLOAK_URL');
|
||||
data.append('client_id', this.CLIENT_ID);
|
||||
data.append('client_secret', this.CLIENT_SECRET);
|
||||
try {
|
||||
const response: AxiosResponse = await axios.post(KEYCLOAK_URL, data, {
|
||||
const response: AxiosResponse = await axios.post(this.KEYCLOAK_URL, data, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
@ -161,39 +185,27 @@ export class AuthService {
|
||||
|
||||
async loginUser(username: string, password: string, req: Request): Promise<any> {
|
||||
|
||||
console.log(username, password);
|
||||
|
||||
|
||||
const accessToken = req.cookies['access_token'];
|
||||
const refreshToken = req.cookies['refresh_token'];
|
||||
|
||||
console.log("---------cookies--------------");
|
||||
console.log(accessToken, refreshToken);
|
||||
|
||||
// return {accessToken, refreshToken, expires_in:2000}
|
||||
|
||||
if (!accessToken && !refreshToken) {
|
||||
|
||||
console.log("I am here getting token ....");
|
||||
|
||||
const url = `${this.configService.get('KEYCLOAK_URL')}/realms/${this.configService.get('REALM')}/protocol/openid-connect/token`;
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.append('grant_type', 'password');
|
||||
params.append('client_id', this.configService.get('CLIENT_ID') || '');
|
||||
params.append('client_secret', this.configService.get('CLIENT_SECRET') || '');
|
||||
params.append('client_id', this.CLIENT_ID);
|
||||
params.append('client_secret', this.CLIENT_SECRET);
|
||||
params.append('username', username);
|
||||
params.append('password', password);
|
||||
|
||||
try {
|
||||
const response = await axios.post(url, params, {
|
||||
const response = await axios.post(this.TOKEN_URL, params, {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
});
|
||||
console.log('first time data ...');
|
||||
|
||||
let k = { ...response.data, email: username };
|
||||
|
||||
return k; // tokens and user info
|
||||
return k;
|
||||
} catch (error) {
|
||||
console.log(error.message);
|
||||
|
||||
@ -206,9 +218,9 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
async getUserIdByEmail() {
|
||||
async getUserIdByEmail(email: string) {
|
||||
|
||||
let url = `${this.configService.get('KEYCLOAK_URL')}/admin/realms/${this.configService.get('REALM')}/users?email=a@gmail.com`;
|
||||
let url = `${this.USERS_URL}?email=${email}`;
|
||||
|
||||
let adminAccessToken = await this.getAdminAccessToken();
|
||||
|
||||
@ -231,37 +243,21 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async forgotPassword() {
|
||||
let urlx = `${this.configService.get('KEYCLOAK_URL')}/admin/realms/${this.configService.get('REALM')}/users`;
|
||||
let urlxx = `${this.configService.get('KEYCLOAK_URL')}/admin/realms/${this.configService.get('REALM')}/users?email=${encodeURIComponent('a@gmail.com')}`;
|
||||
let url = `${this.configService.get('KEYCLOAK_URL')}/admin/realms/${this.configService.get('REALM')}/users?email=a@gmail.com`;
|
||||
|
||||
let validatePasswordURL = `${this.configService.get('KEYCLOAK_URL')}/realms/${this.configService.get('REALM')}/protocol/openid-connect/token`
|
||||
|
||||
const validatePasswordURLSearchParams = new URLSearchParams({
|
||||
grant_type: 'password',
|
||||
client_id: `${this.configService.get('CLIENT_ID')}`,
|
||||
client_secret: `${this.configService.get('CLIENT_SECRET')}`,
|
||||
client_id: `${this.CLIENT_ID}`,
|
||||
client_secret: `${this.CLIENT_SECRET}`,
|
||||
username: `${'a@gmail.com'}`,
|
||||
password: `${'A1!bcdef'}`,
|
||||
});
|
||||
|
||||
let userID = await this.getUserIdByEmail();
|
||||
let userID = await this.getUserIdByEmail("");
|
||||
|
||||
console.log("userID: ", userID);
|
||||
|
||||
let resetPasswordURL = `${this.configService.get('KEYCLOAK_URL')}/admin/realms/${this.configService.get('REALM')}/users/${userID}/reset-password`;
|
||||
let resetPasswordURL = `${this.USERS_URL}/${userID}/reset-password`;
|
||||
|
||||
let adminAccessToken = await this.getAdminAccessToken();
|
||||
|
||||
const options: AxiosRequestConfig = {
|
||||
method: 'GET',
|
||||
url,
|
||||
headers: {
|
||||
Authorization: `Bearer ${adminAccessToken}`,
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
const options1: AxiosRequestConfig = {
|
||||
method: 'PUT',
|
||||
url: resetPasswordURL,
|
||||
@ -277,7 +273,7 @@ export class AuthService {
|
||||
|
||||
const options2: AxiosRequestConfig = {
|
||||
method: 'POST',
|
||||
url: validatePasswordURL,
|
||||
url: this.TOKEN_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
@ -298,16 +294,12 @@ export class AuthService {
|
||||
|
||||
async getAdminAccessToken() {
|
||||
try {
|
||||
const adminTokenUrl = `${this.configService.get('KEYCLOAK_URL')}/realms/${this.configService.get('REALM')}/protocol/openid-connect/token`;
|
||||
|
||||
console.log(adminTokenUrl);
|
||||
|
||||
const adminParams = new URLSearchParams();
|
||||
adminParams.append('grant_type', 'client_credentials');
|
||||
adminParams.append('client_id', this.configService.get('CLIENT_ID') || '');
|
||||
adminParams.append('client_secret', this.configService.get('CLIENT_SECRET') || '');
|
||||
adminParams.append('client_id', this.CLIENT_ID);
|
||||
adminParams.append('client_secret', this.CLIENT_SECRET);
|
||||
|
||||
const adminTokenResponse = await axios.post(adminTokenUrl,
|
||||
const adminTokenResponse = await axios.post(this.TOKEN_URL,
|
||||
adminParams,
|
||||
{
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
@ -324,35 +316,10 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async registerUser(body: AuthLoginDTO, req: Request) {
|
||||
// First, get an admin access token using client credentials
|
||||
let det = await req['user'];
|
||||
|
||||
if (det?.email !== body.P_EMAILADDR) {
|
||||
throw new BadRequestException();
|
||||
}
|
||||
|
||||
const adminTokenUrl = `${this.configService.get('KEYCLOAK_URL')}/realms/${this.configService.get('REALM')}/protocol/openid-connect/token`;
|
||||
|
||||
console.log(adminTokenUrl);
|
||||
|
||||
const adminParams = new URLSearchParams();
|
||||
adminParams.append('grant_type', 'client_credentials');
|
||||
adminParams.append('client_id', this.configService.get('CLIENT_ID') || '');
|
||||
adminParams.append('client_secret', this.configService.get('CLIENT_SECRET') || '');
|
||||
|
||||
const adminTokenResponse = await axios.post(adminTokenUrl,
|
||||
adminParams,
|
||||
{
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
});
|
||||
console.log(adminTokenResponse.data);
|
||||
|
||||
// const adminAccessToken = adminTokenResponse.data.access_token;
|
||||
const adminAccessToken = adminTokenResponse.data.access_token;
|
||||
|
||||
// Now create user
|
||||
const createUserUrl = `${this.configService.get('KEYCLOAK_URL')}/admin/realms/${this.configService.get('REALM')}/users`;
|
||||
|
||||
const userPayload = {
|
||||
username: body.P_EMAILADDR,
|
||||
// firstName:"A",
|
||||
@ -371,9 +338,10 @@ export class AuthService {
|
||||
|
||||
console.log(userPayload);
|
||||
|
||||
const adminAccessToken = await this.getAdminAccessToken();
|
||||
|
||||
try {
|
||||
const response = await axios.post(createUserUrl, userPayload, {
|
||||
const response = await axios.post(this.USERS_URL, userPayload, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${adminAccessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
@ -381,6 +349,13 @@ export class AuthService {
|
||||
});
|
||||
|
||||
if (response.status === 201) {
|
||||
|
||||
const uid = await this.getUserIdByEmail(body.P_EMAILADDR);
|
||||
|
||||
const res = await this.assignRoleToUser(uid, "ca");
|
||||
|
||||
console.log(res);
|
||||
|
||||
return { message: 'User created successfully' };
|
||||
}
|
||||
|
||||
@ -397,11 +372,11 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async logoutUser(refreshToken: string): Promise<any> {
|
||||
const url = `${this.configService.get('KEYCLOAK_URL')}/realms/${this.configService.get('REALM')}/protocol/openid-connect/logout`;
|
||||
const url = `${this.KEYCLOAK_BASE_URL}/logout`;
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.append('client_id', this.configService.get('CLIENT_ID') || '');
|
||||
params.append('client_secret', this.configService.get('CLIENT_SECRET') || '');
|
||||
params.append('client_id', this.CLIENT_ID);
|
||||
params.append('client_secret', this.CLIENT_SECRET);
|
||||
params.append('refresh_token', refreshToken);
|
||||
|
||||
try {
|
||||
@ -414,6 +389,104 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
async getClientUUID(): Promise<string> {
|
||||
try {
|
||||
const token = await this.getAdminAccessToken();
|
||||
|
||||
const realm = this.KEYCLOAK_REALM;
|
||||
const clientId = this.CLIENT_ID;
|
||||
const keycloakUrl = this.KEYCLOAK_URL;
|
||||
|
||||
const response = await axios.get(
|
||||
`${keycloakUrl}/admin/realms/${realm}/clients?clientId=${encodeURIComponent(clientId)}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
validateStatus: () => true, // manually handle status codes
|
||||
}
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error(`Failed to fetch client list. Status: ${response.status}. Message: ${JSON.stringify(response.data)}`);
|
||||
}
|
||||
|
||||
const clients = response.data;
|
||||
|
||||
if (!Array.isArray(clients) || clients.length === 0) {
|
||||
throw new Error(`Client with ID '${clientId}' not found in realm '${realm}'.`);
|
||||
}
|
||||
|
||||
const clientUUID = clients[0].id;
|
||||
|
||||
if (!clientUUID) {
|
||||
throw new Error(`Client UUID is missing in the response for clientId '${clientId}'.`);
|
||||
}
|
||||
|
||||
return clientUUID;
|
||||
} catch (error) {
|
||||
console.error('❌ Error in getClientUUID:', error.message || error);
|
||||
throw error; // rethrow for upstream handling
|
||||
}
|
||||
}
|
||||
|
||||
async getClientRole(roleName: string): Promise<any> {
|
||||
const token = await this.getAdminAccessToken();
|
||||
|
||||
const clientUUID = await this.getClientUUID();
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`${this.KEYCLOAK_URL}/admin/realms/${this.KEYCLOAK_REALM}/clients/${clientUUID}/roles/${roleName}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error(`Error getting client role '${roleName}'`);
|
||||
console.error(error.response?.data || error.message);
|
||||
throw new InternalServerErrorException(`Could not find client role '${roleName}'`);
|
||||
}
|
||||
}
|
||||
|
||||
async assignRoleToUser(userId: string, roleName: string): Promise<any> {
|
||||
try {
|
||||
const token = await this.getAdminAccessToken();
|
||||
|
||||
const clientId = await this.getClientUUID();
|
||||
|
||||
const role = await this.getClientRole(roleName);
|
||||
|
||||
const url = `${this.KEYCLOAK_URL}/admin/realms/${this.KEYCLOAK_REALM}/users/${userId}/role-mappings/clients/${clientId}`;
|
||||
|
||||
const response = await axios.post(
|
||||
url,
|
||||
[role],
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
validateStatus: () => true, // To manually check status if needed
|
||||
}
|
||||
);
|
||||
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
console.log(`✅ Role "${roleName}" successfully assigned to user ${userId}.`);
|
||||
|
||||
return { message: "Successfully assigned to user" }
|
||||
} else {
|
||||
throw new Error(`❌ Failed to assign role. Status: ${response.status}. Data: ${JSON.stringify(response.data)}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`🔥 Error assigning role "${roleName}" to user ${userId}:`, error.message || error);
|
||||
throw error; // Rethrow to allow upstream handling
|
||||
}
|
||||
}
|
||||
|
||||
async getTokenFromRefreshToken(req: Request) {
|
||||
const refreshToken = req.cookies['refresh_token'];
|
||||
|
||||
@ -421,35 +494,18 @@ export class AuthService {
|
||||
throw new UnauthorizedException('Authentication failed');
|
||||
}
|
||||
|
||||
let dk = await this.introspectToken(refreshToken);
|
||||
|
||||
console.log('--------------validation------------------------');
|
||||
console.log(dk);
|
||||
|
||||
console.log('--------------validation------------------------');
|
||||
|
||||
const url = `${this.configService.get('KEYCLOAK_URL')}/realms/${this.configService.get('REALM')}/protocol/openid-connect/token`;
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.append('grant_type', 'refresh_token');
|
||||
params.append('client_id', this.configService.get('CLIENT_ID') || '');
|
||||
params.append('client_secret', this.configService.get('CLIENT_SECRET') || '');
|
||||
params.append('client_id', this.CLIENT_ID);
|
||||
params.append('client_secret', this.CLIENT_SECRET);
|
||||
params.append('refresh_token', refreshToken);
|
||||
|
||||
try {
|
||||
const response = await axios.post(url, params, {
|
||||
const response = await axios.post(this.TOKEN_URL, params, {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
});
|
||||
|
||||
console.log('refresh token response...');
|
||||
console.log(response.data);
|
||||
|
||||
return response.data; // tokens and user info
|
||||
|
||||
// console.log(response.data);
|
||||
|
||||
// return { message: "tokens refreshed successfully...." }
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.log(error.message);
|
||||
throw new UnauthorizedException('Authentication failed');
|
||||
|
||||
5
src/decorators/roles.decorator.ts
Normal file
5
src/decorators/roles.decorator.ts
Normal file
@ -0,0 +1,5 @@
|
||||
// roles.decorator.ts
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
|
||||
export const ROLES_KEY = 'roles';
|
||||
export const Roles = (...roles: string[]) => SetMetadata(ROLES_KEY, roles);
|
||||
11
src/main.ts
11
src/main.ts
@ -7,6 +7,7 @@ import {
|
||||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
||||
import { SwaggerDocumentOptions } from '@nestjs/swagger';
|
||||
import { BadRequestException } from './exceptions/badRequest.exception';
|
||||
import * as cookieParser from 'cookie-parser';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, {
|
||||
@ -20,23 +21,17 @@ async function bootstrap() {
|
||||
},
|
||||
});
|
||||
|
||||
app.use(cookieParser());
|
||||
|
||||
|
||||
function extractConstraints(validationErrors: ValidationError[]) {
|
||||
const constraints: { [key: string]: string }[] = [];
|
||||
|
||||
function traverse(errors: ValidationError[]) {
|
||||
// console.log(errors);
|
||||
// console.log("--------------");
|
||||
for (const error of errors) {
|
||||
// If the error has constraints, add them to the list
|
||||
|
||||
// console.log(error);
|
||||
// console.log("--------------");
|
||||
|
||||
if (error.constraints) {
|
||||
constraints.push(error.constraints);
|
||||
}
|
||||
// // If there are children, recursively traverse them
|
||||
if (error.children && error.children.length > 0) {
|
||||
traverse(error.children);
|
||||
}
|
||||
|
||||
@ -11,9 +11,11 @@ import {
|
||||
UpdateExpGoodsAuthRepDTO,
|
||||
UpdateShippingDetailsDTO
|
||||
} from 'src/dto/property.dto';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
|
||||
@ApiTags('Carnet Application - Oracle')
|
||||
@Roles('ca', 'sa')
|
||||
@Controller('oracle')
|
||||
export class CarnetApplicationController {
|
||||
|
||||
@ -27,11 +29,13 @@ export class CarnetApplicationController {
|
||||
}
|
||||
|
||||
@Post('TransmitApplicationtoProcess')
|
||||
@Roles('ca')
|
||||
TransmitApplicationtoProcess(@Body() body: TransmitApplicationtoProcessDTO) {
|
||||
return this.carnetApplicationService.TransmitApplicationtoProcess(body);
|
||||
}
|
||||
|
||||
@Post('CreateApplication')
|
||||
@Roles('ca')
|
||||
CreateApplication(@Body() body: CreateApplicationDTO) {
|
||||
return this.carnetApplicationService.CreateApplication(body);
|
||||
}
|
||||
@ -67,19 +71,26 @@ export class CarnetApplicationController {
|
||||
ProcessOriginalCarnet(@Body() body: CarnetProcessingCenterDTO) {
|
||||
return this.carnetApplicationService.ProcessOriginalCarnet(body);
|
||||
}
|
||||
|
||||
@Patch('UpdatePrintCarnet')
|
||||
UpdatePrintCarnet(@Body() body: CarnetProcessingCenterDTO) {
|
||||
return this.carnetApplicationService.UpdatePrintCarnet(body);
|
||||
}
|
||||
|
||||
@Patch('VoidCarnet')
|
||||
@Roles('sa')
|
||||
VoidCarnet(@Body() body: CarnetProcessingCenterDTO) {
|
||||
return this.carnetApplicationService.VoidCarnet(body);
|
||||
}
|
||||
|
||||
@Patch('DuplicateCarnet')
|
||||
@Roles('ca')
|
||||
DuplicateCarnet(@Body() body: CarnetProcessingCenterDTO) {
|
||||
return this.carnetApplicationService.DuplicateCarnet(body);
|
||||
}
|
||||
|
||||
@Patch('CloseCarnet')
|
||||
@Roles('sa')
|
||||
CloseCarnet(@Body() body: CarnetProcessingCenterDTO) {
|
||||
return this.carnetApplicationService.CloseCarnet(body);
|
||||
}
|
||||
|
||||
@ -12,8 +12,10 @@ import {
|
||||
SPID_DTO,
|
||||
USERID_DTO
|
||||
} from 'src/dto/property.dto';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
@ApiTags('HomePage - Oracle')
|
||||
@Roles('ca', 'sa', 'ua')
|
||||
@Controller('oracle')
|
||||
export class HomePageController {
|
||||
constructor(private readonly homePageService: HomePageService) { }
|
||||
@ -33,18 +35,4 @@ export class HomePageController {
|
||||
GetCarnetDetailsbyCarnetStatus(@Param() params: GetCarnetDetailsbyCarnetStatusDTO) {
|
||||
return this.homePageService.GetCarnetDetailsbyCarnetStatus(params);
|
||||
}
|
||||
|
||||
// NOTE : this has been moved to carent-application module
|
||||
|
||||
// @Post('/oracle/SaveCarnetApplication')
|
||||
// SaveCarnetApplication(@Body() body: SaveCarnetApplicationDTO) {
|
||||
// return this.homePageService.SaveCarnetApplication(body);
|
||||
// }
|
||||
|
||||
// NOTE : this has been moved to carent-application module
|
||||
|
||||
// @Post('/oracle/TransmitApplicationtoProcess')
|
||||
// TransmitApplicationtoProcess(@Body() body: TransmitApplicationtoProcessDTO) {
|
||||
// return this.homePageService.TransmitApplicationtoProcess(body);
|
||||
// }
|
||||
}
|
||||
|
||||
@ -9,84 +9,75 @@ import {
|
||||
GetClientDTO,
|
||||
GetPreparersParamDTO, GetPreparersQueryDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO
|
||||
} from 'src/dto/property.dto';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Roles('sa')
|
||||
@Controller('oracle')
|
||||
export class ManageClientsController {
|
||||
constructor(private readonly manageClientsService: ManageClientsService) { }
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
|
||||
@Post('CreateNewClients')
|
||||
async CreateClientData(@Body() body: CreateClientDataDTO) {
|
||||
return this.manageClientsService.CreateClientData(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Put('UpdateClient')
|
||||
async UpdateClient(@Body() body: UpdateClientDTO) {
|
||||
return this.manageClientsService.UpdateClient(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Put('UpdateClientContacts')
|
||||
UpdateClientContacts(@Body() body: UpdateClientContactsDTO) {
|
||||
return this.manageClientsService.UpdateClientContacts(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Put('UpdateClientLocations')
|
||||
UpdateClientLocations(@Body() body: UpdateClientLocationsDTO) {
|
||||
return this.manageClientsService.UpdateClientLocations(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Post('CreateClientContacts')
|
||||
CreateClientContact(@Body() body: CreateClientContactsDTO) {
|
||||
return this.manageClientsService.CreateClientContact(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Patch('SetDefaultClientContacts/:P_SPID/:P_CLIENTCONTACTID/:P_USERID')
|
||||
SetDefaultClientContacts(@Param() param: ClientContactControlsDTO) {
|
||||
return this.manageClientsService.SetDefaultClientContacts(param);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Patch('InactivateClientContacts/:P_SPID/:P_CLIENTCONTACTID/:P_USERID')
|
||||
InactivateClientContacts(@Param() param: ClientContactControlsDTO) {
|
||||
return this.manageClientsService.InactivateClientContacts(param);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Patch('ReactivateClientContacts/:P_SPID/:P_CLIENTCONTACTID/:P_USERID')
|
||||
ReactivateClientContacts(@Param() param: ClientContactControlsDTO) {
|
||||
return this.manageClientsService.ReactivateClientContacts(param);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Post('CreateClientLocations')
|
||||
CreateClientLocation(@Body() body: CreateClientLocationsDTO) {
|
||||
return this.manageClientsService.CreateClientLocation(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Get('GetPreparers/:P_SPID/:P_STATUS')
|
||||
async GetPreparers(@Param() param: GetPreparersParamDTO, @Query() query: GetPreparersQueryDTO) {
|
||||
return await this.manageClientsService.GetPreparers({ ...param, ...query });
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Get('GetPreparerByClientid/:P_SPID/:P_CLIENTID')
|
||||
GetPreparerByClientid(@Param() body: GetClientDTO) {
|
||||
return this.manageClientsService.GetPreparerByClientid(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Get('GetPreparerContactsByClientid/:P_SPID/:P_CLIENTID')
|
||||
GetPreparerContactsByClientid(@Param() body: GetClientDTO) {
|
||||
return this.manageClientsService.GetPreparerContactsByClientid(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Get('GetPreparerLocByClientid/:P_SPID/:P_CLIENTID')
|
||||
GetPreparerLocByClientid(@Param() body: GetClientDTO) {
|
||||
return this.manageClientsService.GetPreparerLocByClientid(body);
|
||||
|
||||
@ -7,134 +7,117 @@ import {
|
||||
CreateEfFeeDTO, CreateFeeCommDTO, GetFeeGeneralDTO, UpdateBasicFeeDTO, UpdateBondRateDTO,
|
||||
UpdateCargoRateDTO, UpdateCfFeeDTO, UpdateCsFeeDTO, UpdateEfFeeDTO, UpdateFeeCommDTO
|
||||
} from 'src/dto/property.dto';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Roles('sa','ua')
|
||||
@Controller('oracle')
|
||||
export class ManageFeeController {
|
||||
constructor(private readonly manageFeeService: ManageFeeService) { }
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Get('/GetBasicFeeRates/:P_SPID/:P_ACTIVE_INACTIVE')
|
||||
GetBasicFeeRates(@Param() body: GetFeeGeneralDTO) {
|
||||
return this.manageFeeService.GETBASICFEERATES(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Get('/GetBondRates/:P_SPID/:P_ACTIVE_INACTIVE')
|
||||
GetBondRates(@Param() body: GetFeeGeneralDTO) {
|
||||
return this.manageFeeService.GETBONDRATES(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Get('/GetCargoRates/:P_SPID/:P_ACTIVE_INACTIVE')
|
||||
GetCargoRates(@Param() body: GetFeeGeneralDTO) {
|
||||
return this.manageFeeService.GETCARGORATES(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Get('/GetCfFeeRates/:P_SPID/:P_ACTIVE_INACTIVE')
|
||||
GetCfFeeRates(@Param() body: GetFeeGeneralDTO) {
|
||||
return this.manageFeeService.GETCFFEERATES(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Get('/GetCsFeeRates/:P_SPID/:P_ACTIVE_INACTIVE')
|
||||
GetCsFeeRates(@Param() body: GetFeeGeneralDTO) {
|
||||
return this.manageFeeService.GETCSFEERATES(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Get('/GetEfFeeRates/:P_SPID/:P_ACTIVE_INACTIVE')
|
||||
GetEfFeeRates(@Param() body: GetFeeGeneralDTO) {
|
||||
return this.manageFeeService.GETEFFEERATES(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Get('/GetFeeComm/:P_SPID/:P_ACTIVE_INACTIVE')
|
||||
GetFeeComm(@Param() body: GetFeeGeneralDTO) {
|
||||
return this.manageFeeService.GETFEECOMM(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Post('/CreateBasicFee')
|
||||
CreateBasicFee(@Body() body: CreateBasicFeeDTO) {
|
||||
return this.manageFeeService.CREATEBASICFEE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Post('/CreateBondRate')
|
||||
CreateBondRate(@Body() body: CreateBondRateDTO) {
|
||||
return this.manageFeeService.CREATEBONDRATE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Post('/CreateCargoRate')
|
||||
CreateCargoRate(@Body() body: CreateCargoRateDTO) {
|
||||
return this.manageFeeService.CREATECARGORATE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Post('/CreateCfFee')
|
||||
CreateCfFee(@Body() body: CreateCfFeeDTO) {
|
||||
return this.manageFeeService.CREATECFFEE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Post('/CreateCsFee')
|
||||
CreateCsFee(@Body() body: CreateCsFeeDTO) {
|
||||
return this.manageFeeService.CREATECSFEE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Post('/CreateEfFee')
|
||||
CreateEeFee(@Body() body: CreateEfFeeDTO) {
|
||||
return this.manageFeeService.CREATEEFFEE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Post('/CreateFeeComm')
|
||||
CreateFeeComm(@Body() body: CreateFeeCommDTO) {
|
||||
return this.manageFeeService.CREATEFEECOMM(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Patch('/UpdateBasicFee')
|
||||
UpdateBasicFee(@Body() body: UpdateBasicFeeDTO) {
|
||||
return this.manageFeeService.UPDATEBASICFEE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Patch('/UpdateBondRate')
|
||||
UpdateBondRate(@Body() body: UpdateBondRateDTO) {
|
||||
return this.manageFeeService.UPDATEBONDRATE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Patch('/UpdateCargoRate')
|
||||
UpdateCargoRate(@Body() body: UpdateCargoRateDTO) {
|
||||
return this.manageFeeService.UPDATECARGORATE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Patch('/UpdateCfFee')
|
||||
UpdateCfFee(@Body() body: UpdateCfFeeDTO) {
|
||||
return this.manageFeeService.UPDATECFFEE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Patch('/UpdateCsFee')
|
||||
UpdateCsFee(@Body() body: UpdateCsFeeDTO) {
|
||||
return this.manageFeeService.UPDATECSFEE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Patch('/UpdateEfFee')
|
||||
UpdateEfFee(@Body() body: UpdateEfFeeDTO) {
|
||||
return this.manageFeeService.UPDATEEFFEE(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Fee - Oracle')
|
||||
@Patch('/UpdateFeeComm')
|
||||
UpdateFeeComm(@Body() body: UpdateFeeCommDTO) {
|
||||
return this.manageFeeService.UPDATEFEECOMM(body);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,8 +17,10 @@ import {
|
||||
CreateHoldersDTO, GetHolderDTO, HolderActivateOrInactivateDTO,
|
||||
HolderContactActivateOrInactivateDTO, SearchHolderDTO, UpdateHolderContactDTO, UpdateHolderDTO
|
||||
} from 'src/dto/property.dto';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
@ApiTags('Manage Holders - Oracle')
|
||||
@Roles('ca', 'sa')
|
||||
@Controller('oracle')
|
||||
export class ManageHoldersController {
|
||||
constructor(private readonly manageHoldersService: ManageHoldersService) { }
|
||||
|
||||
@ -2,16 +2,21 @@ import { Body, Controller, Get, Patch, Post, Put, Query } from '@nestjs/common';
|
||||
import { ApiQuery, ApiTags } from '@nestjs/swagger';
|
||||
import { ParamTableService } from './param-table.service';
|
||||
|
||||
import { ActivateOrInactivateParamRecordDTO, CreateParamRecordDTO, CreateTableRecordDTO,
|
||||
getParamValuesDTO, UpdateParamRecordDTO } from 'src/dto/property.dto';
|
||||
import {
|
||||
ActivateOrInactivateParamRecordDTO, CreateParamRecordDTO, CreateTableRecordDTO,
|
||||
getParamValuesDTO, UpdateParamRecordDTO
|
||||
} from 'src/dto/property.dto';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
@ApiTags('Param Table - Oracle')
|
||||
@Roles('sa', 'ua')
|
||||
@Controller('oracle')
|
||||
export class ParamTableController {
|
||||
constructor(private readonly paramTableService: ParamTableService) { }
|
||||
|
||||
|
||||
@Get('/GetParamValues')
|
||||
@Roles('ca', 'sa', 'ua')
|
||||
@ApiQuery({
|
||||
name: 'P_SPID',
|
||||
required: false,
|
||||
@ -29,6 +34,7 @@ export class ParamTableController {
|
||||
}
|
||||
|
||||
@Post('/CreateTableRecord')
|
||||
@Roles('ua')
|
||||
createTableRecord(@Body() body: CreateTableRecordDTO) {
|
||||
return this.paramTableService.CREATETABLERECORD(body);
|
||||
}
|
||||
|
||||
@ -3,8 +3,10 @@ import { ApiTags } from '@nestjs/swagger';
|
||||
import { CarnetSequenceService } from './carnet-sequence.service';
|
||||
|
||||
import { SPID_DTO, CreateCarnetSequenceDTO } from 'src/dto/property.dto';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
@ApiTags('Carnet Sequence - Oracle')
|
||||
@Roles('sa', 'ua')
|
||||
@Controller('oracle')
|
||||
export class CarnetSequenceController {
|
||||
constructor(private readonly carnetSequenceService: CarnetSequenceService) { }
|
||||
|
||||
@ -3,10 +3,12 @@ import { RegionService } from './region.service';
|
||||
import { Get, Post, Body, Controller, Patch } from '@nestjs/common';
|
||||
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
import { InsertRegionsDto, UpdateRegionDto } from 'src/dto/property.dto';
|
||||
|
||||
@ApiTags('Regions - Oracle')
|
||||
@Roles('sa', 'ua')
|
||||
@Controller('oracle')
|
||||
export class RegionController {
|
||||
constructor(private readonly regionService: RegionService) { }
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { SpContactsService } from './sp-contacts.service';
|
||||
import { Body, Controller, Get, Param, Patch, Post, Put, Query } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
import {
|
||||
SPID_DTO,
|
||||
@ -9,6 +10,7 @@ import {
|
||||
} from 'src/dto/property.dto';
|
||||
|
||||
@ApiTags('SPContacts - Oracle')
|
||||
@Roles('sa', 'ua')
|
||||
@Controller('oracle')
|
||||
export class SpContactsController {
|
||||
constructor(private readonly spContactsService: SpContactsService) { }
|
||||
@ -20,6 +22,7 @@ export class SpContactsController {
|
||||
}
|
||||
|
||||
@Patch('/SetSPDefaultContact/:P_SPCONTACTID')
|
||||
@Roles('ua')
|
||||
setSPDefaultcontact(@Param() param: SP_CONTACTID_DTO) {
|
||||
return this.spContactsService.setSPDefaultcontact(param);
|
||||
}
|
||||
|
||||
@ -6,14 +6,17 @@ import {
|
||||
SPID_DTO, InsertNewServiceProviderDTO,
|
||||
UpdateServiceProviderDTO,
|
||||
} from 'src/dto/property.dto';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
@ApiTags('SP - Oracle')
|
||||
@Roles('sa', 'ua')
|
||||
@Controller('oracle')
|
||||
export class SpController {
|
||||
constructor(private readonly spService: SpService) { }
|
||||
|
||||
|
||||
@Post('/InsertNewServiceProvider')
|
||||
@Roles('ua')
|
||||
insertNewServiceProvider(@Body() body: InsertNewServiceProviderDTO) {
|
||||
return this.spService.insertNewServiceProvider(body);
|
||||
}
|
||||
@ -24,6 +27,7 @@ export class SpController {
|
||||
}
|
||||
|
||||
@Get('/GetAllServiceproviders')
|
||||
@Roles('ua')
|
||||
getAllServiceproviders() {
|
||||
return this.spService.getAllServiceproviders();
|
||||
}
|
||||
|
||||
@ -7,8 +7,10 @@ import {
|
||||
EMAIL_DTO, USERID_DTO,
|
||||
CreateClientLoginsDTO, CreateSPLoginsDTO, CreateUSCIBLoginsDTO, SPID_CLIENTID_DTO, SPID_EMAIL_DTO
|
||||
} from 'src/dto/property.dto';
|
||||
import { Roles } from 'src/decorators/roles.decorator';
|
||||
|
||||
@ApiTags('User Maintenance - Oracle')
|
||||
@Roles('ca', 'sa', 'ua')
|
||||
@Controller('oracle')
|
||||
export class UserMaintenanceController {
|
||||
constructor(private readonly userMaintenanceService: UserMaintenanceService) { }
|
||||
@ -28,11 +30,13 @@ export class UserMaintenanceController {
|
||||
// USCIB_LOGINS
|
||||
|
||||
@Get('GetUSCIBLogins')
|
||||
@Roles('ua')
|
||||
async GetUSCIBLogins() {
|
||||
return await this.userMaintenanceService.GetUSCIBLogins();
|
||||
}
|
||||
|
||||
@Post('CreateUSCIBLogins')
|
||||
@Roles('ua')
|
||||
async CreateUSCIBLogins(@Body() body: CreateUSCIBLoginsDTO) {
|
||||
return await this.userMaintenanceService.CreateUSCIBLogins(body);
|
||||
}
|
||||
@ -40,11 +44,13 @@ export class UserMaintenanceController {
|
||||
// SP LOGINS
|
||||
|
||||
@Get('GetSPLogins/:P_SPID')
|
||||
@Roles('sa')
|
||||
async GetSPLogins(@Param() params: SPID_DTO) {
|
||||
return await this.userMaintenanceService.GetSPLogins(params);
|
||||
}
|
||||
|
||||
@Post('CreateSPLogins')
|
||||
@Roles('sa')
|
||||
async CreateSPLogins(@Body() body: CreateSPLoginsDTO) {
|
||||
return await this.userMaintenanceService.CreateSPLogins(body);
|
||||
}
|
||||
@ -52,16 +58,19 @@ export class UserMaintenanceController {
|
||||
// CLIENT LOGINS
|
||||
|
||||
@Get('GetClientloginsBySPID/:P_SPID')
|
||||
@Roles('sa')
|
||||
async GetClientloginsBySPID(@Param() params: SPID_DTO) {
|
||||
return await this.userMaintenanceService.GetSPLogins(params);
|
||||
}
|
||||
|
||||
@Get('GetClientloginsByClientID/:P_SPID/:P_CLIENTID')
|
||||
@Roles('sa')
|
||||
async GetClientloginsByClientID(@Param() params: SPID_CLIENTID_DTO) {
|
||||
return await this.userMaintenanceService.GetSPLogins(params);
|
||||
}
|
||||
|
||||
@Post('CreateClientLogins')
|
||||
@Roles('sa')
|
||||
async CreateClientLogins(@Body() body: CreateClientLoginsDTO) {
|
||||
return await this.userMaintenanceService.CreateClientLogins(body);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user