Skip to content

Commit

Permalink
Merge pull request #177 from arati-tekdi/main
Browse files Browse the repository at this point in the history
API for generate signed URL and save data to salesforce
  • Loading branch information
Shubham4026 authored Mar 3, 2025
2 parents 1dafb73 + 882eceb commit 3d9a975
Show file tree
Hide file tree
Showing 11 changed files with 933 additions and 116 deletions.
485 changes: 465 additions & 20 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@nestjs/swagger": "^5.2.1",
"@nestjs/typeorm": "^10.0.2",
"@types/multer": "^1.4.12",
"aws-sdk": "^2.1692.0",
"axios": "^0.26.1",
"cache-manager": "^3.6.1",
"class-transformer": "^0.5.1",
Expand Down Expand Up @@ -105,4 +106,4 @@
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
}
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewareConsumer, Module } from "@nestjs/common";
import { MiddlewareConsumer, Module, RequestMethod } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
Expand Down
51 changes: 51 additions & 0 deletions src/common/services/upload-S3.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// src/s3.service.ts
import { HttpStatus, Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { S3 } from "aws-sdk";
import APIResponse from "../responses/response";
import { API_RESPONSES } from "@utils/response.messages";
import { APIID } from "@utils/api-id.config";

@Injectable()
export class UploadS3Service {
private s3: S3;
private bucketName: string;

constructor(private configService: ConfigService) {
this.bucketName = this.configService.get("AWS_BUCKET_NAME");
this.s3 = new S3({
accessKeyId: this.configService.get("AWS_ACCESS_KEY_ID"),
secretAccessKey: this.configService.get("AWS_SECRET_ACCESS_KEY"),
region: this.configService.get("AWS_REGION"),
signatureVersion: "v4",
});
}

async getPresignedUrl(key: string, fileType, response): Promise<string> {
try {
const params = {
Bucket: this.bucketName,
Key: key,
Expires: 60 * 5, // URL expires in 5 min
ContentType: fileType,
};

const result = await this.s3.getSignedUrlPromise("putObject", params);
return await APIResponse.success(
response,
APIID.SIGNED_URL,
result,
HttpStatus.OK,
API_RESPONSES.SIGNED_URL_SUCCESS
);
} catch (error) {
return APIResponse.error(
response,
APIID.SIGNED_URL,
API_RESPONSES.BAD_REQUEST,
API_RESPONSES.SIGNED_URL_FAILED,
HttpStatus.BAD_REQUEST
);
}
}
}
3 changes: 2 additions & 1 deletion src/common/utils/api-id.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ export const APIID = {
TENANT_LIST: "api.tenant.list",
SEND_OTP: "api.send.OTP",
VERIFY_OTP: "api.verify.OTP",
SEND_RESET_OTP: "api.send.reset.otp",
SEND_RESET_OTP: 'api.send.reset.otp',
SIGNED_URL: 'api.get.signedURL'
};
178 changes: 102 additions & 76 deletions src/common/utils/response.messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,93 +62,115 @@ export const API_RESPONSES = {
INVALID_FORM: "Invalid form",
TENANTID_MISMATCHED: "Tenant id mismatched",
INVALID_CONTEXT: (context) => `Invalid context: ${context}`,
INVALID_CONTEXTTYPE: (context, validContextTypes) => `Invalid contextType. For the context '${context}', it must be one of: ${validContextTypes}`,
COHORTID_NOTFOUND_FOT_THIS_YEAR: (cohortId) => `Cohort with cohortId ${cohortId} does not exist for this academic year.`,
MAPPING_EXIST_BW_USER_AND_COHORT: (userId, cohortId) => `Mapping already exists for userId ${userId} and cohortId ${cohortId} for this academic year`,
COHORT_NOTMAPPED_WITH_USER: (removeCohortId, userId) => `Cohort Id ${removeCohortId} is not mapped to user Id${userId}} for this academic year.`,
COHORT_STATUS_UPDATED_FOR_USER: (removeCohortId, userId) => `Cohort Id ${removeCohortId} status updated for This user Id${userId}}`,
ERROR_UPDATE_COHORTMEMBER: (userId, removeCohortId, error) => `Error updating cohort member with userId ${userId} and cohortId ${removeCohortId}: ${error}`,
ERROR_SAVING_COHORTMEMBER: (userId, cohortId, error) => `Error saving cohort member with userId ${userId} and cohortId ${cohortId}: ${error}`,
USER_NOTEXIST: (userId) => `User with userId ${userId} does not exist for this academic year.`,
UNAUTHORIZED: 'Unauthorized',
INVALID_TOKEN: 'Token Invalid',
INVALID_CONTEXTTYPE: (context, validContextTypes) =>
`Invalid contextType. For the context '${context}', it must be one of: ${validContextTypes}`,
COHORTID_NOTFOUND_FOT_THIS_YEAR: (cohortId) =>
`Cohort with cohortId ${cohortId} does not exist for this academic year.`,
MAPPING_EXIST_BW_USER_AND_COHORT: (userId, cohortId) =>
`Mapping already exists for userId ${userId} and cohortId ${cohortId} for this academic year`,
COHORT_NOTMAPPED_WITH_USER: (removeCohortId, userId) =>
`Cohort Id ${removeCohortId} is not mapped to user Id${userId}} for this academic year.`,
COHORT_STATUS_UPDATED_FOR_USER: (removeCohortId, userId) =>
`Cohort Id ${removeCohortId} status updated for This user Id${userId}}`,
ERROR_UPDATE_COHORTMEMBER: (userId, removeCohortId, error) =>
`Error updating cohort member with userId ${userId} and cohortId ${removeCohortId}: ${error}`,
ERROR_SAVING_COHORTMEMBER: (userId, cohortId, error) =>
`Error saving cohort member with userId ${userId} and cohortId ${cohortId}: ${error}`,
USER_NOTEXIST: (userId) =>
`User with userId ${userId} does not exist for this academic year.`,
UNAUTHORIZED: "Unauthorized",
INVALID_TOKEN: "Token Invalid",
INVALID_OPTION: 'Invalid Option Selected',

//User Api messages
USER_UPDATED_SUCCESSFULLY: 'User updated successfully.',
USER_NOT_EXISTS: 'User does not exist.',
USER_EXISTS: 'User already exist.',
DUPLICATE_DATA: 'Duplicate data.',
USER_ALREADY_EXISTS: 'User already exists.',
SERVER_ERROR: 'Internal server error',
SERVICE_NAME: 'User service',
USER_UPDATED_SUCCESSFULLY: "User updated successfully.",
USER_NOT_EXISTS: "User does not exist.",
USER_EXISTS: "User already exist.",
DUPLICATE_DATA: "Duplicate data.",
USER_ALREADY_EXISTS: "User already exists.",
SERVER_ERROR: "Internal server error",
SERVICE_NAME: "User service",


USER_NOT_FOUND_FOR_DELETE: 'User not found for delete.',
USER_NOT_FOUND_FOR_PASSWORD_RESET: 'User not found for password reset.',
USER_NOT_FOUND_FOR_DELETE: "User not found for delete.",
USER_NOT_FOUND_FOR_PASSWORD_RESET: "User not found for password reset.",

//get User Details
USER_GET_SUCCESSFULLY: 'User details fetched successfully.',
USER_GET_BY_EMAIL_SUCCESSFULLY: 'User details fetched successfully by email',
USER_GET_BY_PHONE_SUCCESSFULLY: 'User details fetched successfully by phone',
USER_GET_BY_USERNAME_SUCCESSFULLY: 'User details fetched successfully by username',
USER_GET_BY_TENANT_ID_SUCCESSFULLY: 'User details fetched successfully by tenantId',
USER_GET_BY_USER_ID_SUCCESSFULLY: 'User details fetched successfully by userId',
USER_GET_BY_USER_ID_AND_TENANT_ID_SUCCESSFULLY: 'User details fetched successfully by userId and tenantId',
USER_GET_BY_EMAIL_AND_TENANT_ID_SUCCESSFULLY: 'User details fetched successfully by email and tenantId',
USER_CREATE_KEYCLOAK: 'User created successfully on keycloak',
USER_GET_SUCCESSFULLY: "User details fetched successfully.",
USER_GET_BY_EMAIL_SUCCESSFULLY: "User details fetched successfully by email",
USER_GET_BY_PHONE_SUCCESSFULLY: "User details fetched successfully by phone",
USER_GET_BY_USERNAME_SUCCESSFULLY:
"User details fetched successfully by username",
USER_GET_BY_TENANT_ID_SUCCESSFULLY:
"User details fetched successfully by tenantId",
USER_GET_BY_USER_ID_SUCCESSFULLY:
"User details fetched successfully by userId",
USER_GET_BY_USER_ID_AND_TENANT_ID_SUCCESSFULLY:
"User details fetched successfully by userId and tenantId",
USER_GET_BY_EMAIL_AND_TENANT_ID_SUCCESSFULLY:
"User details fetched successfully by email and tenantId",
USER_CREATE_KEYCLOAK: "User created successfully on keycloak",
USERNAME_EXISTS_KEYCLOAK: 'Username is already exists in keycloak',
UPDATE_USER_KEYCLOAK_ERROR:'Failed to update username details in Keycloak.',
USERNAME_SUGGEST_SUCCESSFULLY:'Username is already taken. Suggested a new unique username.',

//Create user
USER_CREATE_SUCCESSFULLY: `User created successfully`,
USER_CREATE_IN_DB: 'User created in user table successfully',
USER_CREATE_FAILED: 'User creation failed',
USER_CREATE_FAILED_WITH_ERROR: (error) => `User creation failed with error: ${error}`,
USER_CREATE_FAILED_WITH_ERROR_AND_EMAIL: (error, email) => `User creation failed with error: ${error}. Email: ${email}`,
USER_CREATE_FAILED_WITH_ERROR_AND_PHONE: (error, phone) => `User creation failed with error: ${error}. Phone: ${phone}`,
USER_CREATE_FAILED_WITH_ERROR_AND_USERNAME: (error, username) => `User creation failed with error: ${error}. Username: ${username}`,
USER_CREATE_IN_DB: "User created in user table successfully",
USER_CREATE_FAILED: "User creation failed",
USER_CREATE_FAILED_WITH_ERROR: (error) =>
`User creation failed with error: ${error}`,
USER_CREATE_FAILED_WITH_ERROR_AND_EMAIL: (error, email) =>
`User creation failed with error: ${error}. Email: ${email}`,
USER_CREATE_FAILED_WITH_ERROR_AND_PHONE: (error, phone) =>
`User creation failed with error: ${error}. Phone: ${phone}`,
USER_CREATE_FAILED_WITH_ERROR_AND_USERNAME: (error, username) =>
`User creation failed with error: ${error}. Username: ${username}`,
USERID_NOT_FOUND: (userId) => `User Id '${userId}' does not exist.`,
TENANTID_NOT_FOUND: (tenantId) => `Tenant Id '${tenantId}' does not exist.`,


//UUID constants
UUID_VALIDATION: 'Please enter valid UUID',
UUID_VALIDATION: "Please enter valid UUID",
INVALID_EMAIL: (emailId) => `Invalid email address: ${emailId}`,
MOBILE_NO_CHECK: (mobileNo) => `Mobile number must be 10 digits long: ${mobileNo}`,
MOBILE_NO_CHECK: (mobileNo) =>
`Mobile number must be 10 digits long: ${mobileNo}`,
DOB_FORMAT: (dob) => `Date of birth must be in the format yyyy-mm-dd: ${dob}`,
INVALID_USERNAME_EMAIL: `Invalid Username Or Email`,
USER_RELATEDENTITY_DELETE: `User and related entries deleted Successfully.`,

ACADEMIC_YEAR_NOT_FOUND: 'Academic year not found for tenant',
DUPLICAT_TENANTID: "Duplicate tenantId detected. Please ensure each tenantId is unique and correct your data.",
INVALID_PARAMETERS: 'Invalid parameters provided. Please ensure that tenantId, roleId, and cohortId (if applicable) are correctly provided.',
COHORT_NOT_FOUND_IN_TENANT_ID: (cohortId, TenantId) => `Cohort Id '${cohortId}' does not exist for this tenant '${TenantId}'.`,
ACADEMIC_YEAR_NOT_FOUND: "Academic year not found for tenant",
DUPLICAT_TENANTID:
"Duplicate tenantId detected. Please ensure each tenantId is unique and correct your data.",
INVALID_PARAMETERS:
"Invalid parameters provided. Please ensure that tenantId, roleId, and cohortId (if applicable) are correctly provided.",
COHORT_NOT_FOUND_IN_TENANT_ID: (cohortId, TenantId) =>
`Cohort Id '${cohortId}' does not exist for this tenant '${TenantId}'.`,

ROLE_NOT_FOUND_IN_TENANT: (roleId, tenantId) => `Role Id '${roleId}' does not exist for this tenant '${tenantId}'.`,
ROLE_NOT_FOUND_IN_TENANT: (roleId, tenantId) =>
`Role Id '${roleId}' does not exist for this tenant '${tenantId}'.`,
USER_EXISTS_SEND_MAIL: "User Exists. Proceed with Sending Email.",
INVALID_FIELD: (invalidateFields) => `Invalid fields found: ${invalidateFields}`,
DUPLICATE_FIELD: (duplicateFieldKeys) => `Duplicate fieldId detected: ${duplicateFieldKeys}`,
FIELD_NOT_FOUND: 'Field not found',
PASSWORD_RESET: 'Password reset successful!',
INVALID_FIELD: (invalidateFields) =>
`Invalid fields found: ${invalidateFields}`,
DUPLICATE_FIELD: (duplicateFieldKeys) =>
`Duplicate fieldId detected: ${duplicateFieldKeys}`,
FIELD_NOT_FOUND: "Field not found",
PASSWORD_RESET: "Password reset successful!",

SOMETHING_WRONG: "Something went wrong",
USER_PASSWORD_UPDATE: "User Password Updated Successfully",
USER_BASIC_DETAILS_UPDATE: "User basic details updated successfully",
USER_TENANT: "User tenant mapping successfully",
USER_COHORT: "User cohort mapping successfully",
COHORT_NAME_EXIST: 'Cohort name already exist.Please provide another name.',
COHORT_NAME_EXIST: "Cohort name already exist.Please provide another name.",

COHORT_LIST: "Cohort list fetched successfully",
COHORT_HIERARCHY: "Cohort hierarchy fetched successfully",
COHORT_EXISTS: 'Cohort already exists',
COHORT_EXISTS: "Cohort already exists",
CREATE_COHORT: "Cohort Created Successfully.",
COHORT_FIELD_DETAILS: 'Fetch cohort custom field details',
CHILD_DATA: 'Get all child data response',
COHORT_DATA_RESPONSE: 'Fetch cohort data response',
COHORT_UPDATED_SUCCESSFULLY: 'Cohort updated successfully.',
TENANT_NOTFOUND: 'Tenant not found',
COHORT_FIELD_DETAILS: "Fetch cohort custom field details",
CHILD_DATA: "Get all child data response",
COHORT_DATA_RESPONSE: "Fetch cohort data response",
COHORT_UPDATED_SUCCESSFULLY: "Cohort updated successfully.",
TENANT_NOTFOUND: "Tenant not found",
COHORTMEMBER_UPDATE_SUCCESSFULLY: "Cohort Member updated Successfully",

//Tenant
Expand All @@ -162,29 +184,33 @@ export const API_RESPONSES = {
TENANT_CREATE_FAILED: "Failed to create tenant, please try again.",
REQUIRED_AND_UUID: "tenantId is required and it's must be a valid UUID.",


//OTP
NOTIFICATION_FAIL_DURING_OTP_SEND: "Send SMS notification failed duing OTP send",
NOTIFICATION_FAIL_DURING_OTP_SEND:
"Send SMS notification failed duing OTP send",
OTP_SEND_SUCCESSFULLY: "OTP sent successfully",
OTP_EXPIRED: 'OTP has expired',
OTP_EXPIRED: "OTP has expired",
OTP_INVALID: "OTP invalid",
OTP_VALID: 'OTP validation Sucessfully',
MOBILE_VALID: 'Invalid mobile number. Must be 10 digits.',
OTP_VALIDED_REQUIRED_KEY: 'Missing required fields',
INVALID_HASH_FORMATE: 'Invalid hash format',
SMS_ERROR: 'SMS notification failed',
SMS_NOTIFICATION_ERROR: 'Failed to send SMS notification:',
USERNAME_REQUIRED: 'Username Required',
INVALID_REASON: 'Invalid Reason',
MOBILE_REQUIRED: 'MObile Required',
INVALID_HASH_FORMAT: 'Invalid hash format',
NOTIFICATION_ERROR: 'Notification not send due to getting from notification API',
MOBILE_EMAIL_NOT_FOUND: 'Mobile number and email ID not found for sending OTP',
MOBILE_SENT_OTP: 'OTP sent successfully to mobile',
MOBILE_OTP_SEND_FAILED: 'Failed to send OTP to mobile',
EMAIL_SENT_OTP: 'OTP sent successfully to email',
EMAIL_OTP_SEND_FAILED: 'Failed to send OTP to email',
SEND_OTP: 'OTP sent successfully',
EMAIL_NOTIFICATION_ERROR: 'Failed to send Email notification:',
EMAIL_ERROR: 'Email notification failed'
OTP_VALID: "OTP validation Sucessfully",
MOBILE_VALID: "Invalid mobile number. Must be 10 digits.",
OTP_VALIDED_REQUIRED_KEY: "Missing required fields",
INVALID_HASH_FORMATE: "Invalid hash format",
SMS_ERROR: "SMS notification failed",
SMS_NOTIFICATION_ERROR: "Failed to send SMS notification:",
USERNAME_REQUIRED: "Username Required",
INVALID_REASON: "Invalid Reason",
MOBILE_REQUIRED: "MObile Required",
INVALID_HASH_FORMAT: "Invalid hash format",
NOTIFICATION_ERROR:
"Notification not send due to getting from notification API",
MOBILE_EMAIL_NOT_FOUND:
"Mobile number and email ID not found for sending OTP",
MOBILE_SENT_OTP: "OTP sent successfully to mobile",
MOBILE_OTP_SEND_FAILED: "Failed to send OTP to mobile",
EMAIL_SENT_OTP: "OTP sent successfully to email",
EMAIL_OTP_SEND_FAILED: "Failed to send OTP to email",
SEND_OTP: "OTP sent successfully",
EMAIL_NOTIFICATION_ERROR: "Failed to send Email notification:",
EMAIL_ERROR: "Email notification failed",
SIGNED_URL_SUCCESS: "Signed URL generated successfully",
SIGNED_URL_FAILED: "Error while generating signed URL",
};
Loading

0 comments on commit 3d9a975

Please sign in to comment.