Skip to content

Instantly share code, notes, and snippets.

@jspw
Last active May 16, 2024 19:05
Show Gist options
  • Save jspw/b100f75fa60a7792bde2318644827eb1 to your computer and use it in GitHub Desktop.
Save jspw/b100f75fa60a7792bde2318644827eb1 to your computer and use it in GitHub Desktop.
CRM_APPLICATION_SETUP_GUIDE
  1. Connection Between Client CRM & Intra CRM
  2. Intra CRM Backend
  3. Intra CRM Frontend

Connection Between Client CRM & Intra CRM

Note: These steps are only for the first time setup.

Intra CRM Backend

How to config/setup

sample env file
SERVER_PORT=the_port_you_want_to_run_intra_crm_backend_application
LOG_DIR=logs
ERROR_LOG_FILE=error.log
ALL_LOG_FILE=all.log
ENVIRONMENT=production
MYSQL_DB_HOST=your_mysql_database_url
MYSQL_DB_PORT=your_mysql_database_port(default port 3306)
MYSQL_DB_NAME=your_mysql_database_name(i was using Intra_CRM)
MYSQL_DB_USER=your_mysql_database_user_name(can be root)
MYSQL_DB_PASSWORD=your_mysql_database_user_password
DB_DIALECT=mysql
JWT_SECRET=jwt_secret_token_for_jwt_token_generate
JWT_TOKEN_EXPIRE_IN=120d
CV_LIBRARY_BASE_URL=https://jobs-api-2pfgldu3uq-nw.a.run.app
CV_LIBRARY_API_KEY=cv_lib_api_key
CV_LIBRARY_USER_PASSWORD=cv_lib_default_password
SUPER_ADMIN_TOKEN=intra_crm_super_admin_key
SPYRE_CRM_BASE_URL=clinet_crm_backend_base_url
SPYRE_CRM_API_SECRET_KEY=client_crm_admin_token (you can create an admin from clinet crm backend with "/auth/createAdmin" endpoiint and use "CLIENT_CRM_BACKEND_SUPER_TOKEN" env variable as token in the post request body)
CLIENT_CRM_BACKEND_SUPER_TOKEN=clinet_crm_super_token_will_be used_while_creating_admins_from_intra_crm_backend(endpoint POST: "/users")
CLIENT_DEFAULT_PASSWORD=the_default_password_while_creating_client_from_CLIENT_DASHBPARD_in_intra_crm
CLOWN_FISH_API=https://clownfish-app-lryu4.ondigitalocean.app/api/create
CLOWN_FISH_API_KEY=#$$8sflkj@(ACMEU8m,
TOTAL_JOBS_API=https://totaljobs-2pfgldu3uq-nw.a.run.app
TOTAL_JOBS_API_KEY=d5fb8c4fa8bd46638dadc4e751e0d68d
TOTAL_JOBS_USER_PASSWORD=England@123

DB Config

as we are using join of multiple tables in some api calls, you need to setup/config the database for the first time.

  • login to your mysql shell
  • Run the command

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

How to run

Install dependencies

npm install

Build

npm run build

Run

npm start

Usages

Create Admin From Intra_CRM

Pre-requirements

make sure your .env file has the environment variable CLIENT_CRM_BACKEND_SUPER_TOKEN.

How to create

use postman or any other tool. You need to hit a POST api call on /users endpoint.

METHOD: POST

ENDPOINT: /users

AUTH: Bearer token from env file "SUPER_ADMIN_TOKEN"

Request Body:

{
    "firstName" : string,
    "lastName" : string,
    "email": string/email,
    "role" : "Admin",
    "password": string
}

RESPONSE:

{
    "id": int,
    "name": string,
    "email": string,
    "role": "Admin",
    "clientCRMToken": string,
    "userId": string,
    "updatedAt": string (Date),
    "createdAt": string (Date)
}

SAMPLE:

POST /users

BEARER TOKEN: mynameismehedihasanshifatandiamnotasoftwareengineer

body:

{
  "firstName" : "Intra",
  "lastName" : "CRM",
  "email": "mhshifat@spyre.co",
  "role" : "Admin",
  "password":"England@123"
}

Response:

{
  "id": 4,
  "name": "Intra CRM",
  "email": "mhshifat@spyre.co",
  "role": "Admin",
  "clientCRMToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0ODU3ZmYwZS1iNGZlLTRmMmItOTljYy02ZTZkN2E3NWQyZTkiLCJlbWFpbCI6Im1oc2hpZmF0QHNweXJlLmNvIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNzEwMDU5NDEwLCJleHAiOjQ4NjU4MTk0MTB9.5gjjGPxEtPcGj8M6aC_rbbxfQvD3359P3-koAMJ7dn4",
  "userId": "4857ff0e-b4fe-4f2b-99cc-6e6d7a75d2e9",
  "updatedAt": "2024-03-10T08:30:10.900Z",
  "createdAt": "2024-03-10T08:30:10.900Z"
}

how this works?

when you are creating an admin from intra crm backend, it will create an admin in client crm backend and then save it into intra crm backend too. So, make sure this email doesn't exist already in intra_crm or client_crm either.

Generate Token for other services

Admin Token Generate

METHOD: POST

ENDPOINT: /generate-token

AUTH: Bearer token from env file "SUPER_ADMIN_TOKEN"

REQUEST BODY:

{
    "role": "ADMIN"
}

RESPONSE BODY:

{
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MCwiZW1haWwiOiJ0ZXN0MTIzQGdtYWlsLmNvbSIsInJvbGUiOiJBRE1JTiIsImlhdCI6MTcxMDA1OTg4NCwiZXhwIjoxNzIwNDI3ODg0fQ.-YZ-IunQJssyXU9nFPj5z4hnRYk38lXPyV6mo-2AcpQ",
    "expiresIn": "120d",
    "role": "ADMIN"
}

Note: You can obviously get a token by just login with the credential after creating an admin account too.

Intra CRM Frontend

Sample ENV file

NEXT_PUBLIC_API_BASE_URL=http://localhost:5001
NEXTAUTH_SECRET="@#$Sc.wopux5642DFs24gdd"
NEXTAUTH_URL=http://localhost:3001
  • NEXT_PUBLIC_API_BASE_URL refers to the intra-crm-backend base url
  • NEXTAUTH_URL refers to the intra-crm-frontend base url

Issues

  • if facing any issue related to login then try to clear the localstorage and reload the page or login again.
@jspw
Copy link
Author

jspw commented May 16, 2024

Signup API

Fetch Info From CV

Method: POST

Endpoint: /auth/fetchSignupInfoFromCv

Req body: (just like signUpWithCV endpoint)

{
  "file": "string($binary)"
}

Response:

{
  "status": "success",
  "message": "Initial User created successfully. Please check email to verify your email",
  "data": {
    "userId": "c7ac4c35-ec8f-4226-a408-3f2b6eff4687",
    "cvLibUserId": 1715754942923,
    "email": "inewton8@icloud.com",
    "firstName": "Isaac",
    "lastName": "Newton",
    "location": "Manchester",
    "county": "Greater Manchester",
    "postcode": "M2 3GX",
    "phone": "07562913859",
    "role": "client",
    "isCvProcessing": true,
    "isActive": false,
    "cvUrl": "uploaded-files/users/c7ac4c35-ec8f-4226-a408-3f2b6eff4687/upload/ba05fdcb-41dd-4b48-92f4-e831f18e0cd1.docx",
    "isPhoneActive": false,
    "isEmailActive": false,
    "profileImageUrl": "0",
    "hasUploadedCV": false,
    "isCvValuatorProcessing": false,
    "status": "offline",
    "createdAt": "2024-05-15T00:35:42.971Z",
    "updatedAt": "2024-05-15T00:35:42.000Z",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjN2FjNGMzNS1lYzhmLTQyMjYtYTQwOC0zZjJiNmVmZjQ2ODciLCJlbWFpbCI6ImluZXd0b244QGljbG91ZC5jb20iLCJyb2xlIjoiY2xpZW50IiwiaWF0IjoxNzE1NzU0OTQyLCJleHAiOjE3MTcwNTA5NDJ9.3FmGdKn8D9BZQOYk17fh7FyxkypnvwxpxWHrcTqMt_8"
  }
}

Signup with fetched info from CV

Method: POST

Endpoint: /auth/signupWithInfoFromCV

Req body: (just like signUpWithCV endpoint)

class SignupWithCVInfoDto {
  @ApiProperty({
    description: "User ID"
  })
  @IsString()
  @IsOptional()
  userId: string;

  @ApiProperty({
    description: "First Name"
  })
  @IsString()
  @IsNotEmpty()
  firstName: string;

  @ApiProperty({
    description: "Last Name"
  })
  @IsString()
  @IsNotEmpty()
  lastName: string;

  @ApiProperty({
    description: "Email"
  })
  @IsEmail()
  @IsNotEmpty()
  email: string;

  @ApiProperty({
    description: "Phone Number"
  })
  @IsString()
  @IsNotEmpty()
  phone: string;

  @ApiProperty({
    description: "Password"
  })
  @IsString()
  @IsNotEmpty()
  @IsStrongPassword()
  password: string;

  @ApiProperty({
    description: "county"
  })
  @IsString()
  @IsNotEmpty()
  county: string;

  @ApiProperty({
    description: "postcode"
  })
  @IsString()
  @IsNotEmpty()
  postcode: string;

  @ApiProperty({
    description: "location"
  })
  @IsString()
  @IsNotEmpty()
  location: string;
}

Response:

{
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment