New project setup from past project

  1. Go in folder where you want to clone the project. Do not create folder as folder will create automatically using the git clone command
  2. Make sure you do not go inside any folder, must be on root of you project folder
  3. Go to gitlab and copy ssh path commandgit clone ssh://git@cicd.thatsend.one:8222/source-code/api/uklix.com_api.git>
  4. You need to replace uklix.com_api.git as per your releavnt prject repo
  5. You will see a new folder created in your directory which is your project.
  6. Open that folder as a project in visual code
  7. Now copy the relavant past project without node_module dist .git .gitlab-ci.yml Make sure you enable hidden files and folders and check.
  8. Clean up the past project data. Genearlly we need to remove apps/shared-app/src/business Remove all folders but keep business.enum.ts, business.module.ts, business.service.ts
  9. Remove all relations from the master modules
  10. Remove all modules from the Import and Exports from the business.module.ts
  11. Now, we need to install all command using npm intsall OR npm i
  12. Now, need to setup database and get the basic information of database
  13. Import database from the past project and remove unwanted data from the tables

    Remove except the anonymous user from below tables

    1. te_user
    2. te_user_authentication
    3. te_user_authorisation

    Truncate below tables

    1. te_user_device
    2. te_session
  14. we need to change env/.env, env/production.env, env/test.env, env/development.env
  15. Need to change below config in .env file.

    1. TZ set relevat timezone
    2. PROJECT_NAME set relevat project name
    3. COOKIE_SECRET Run command openssl enc -aes-256-cbc -k MySuperSecretPassPhrase -P -md sha1 and copy key
    4. SESSION_SECRET Run command openssl enc -aes-256-cbc -k MySuperSecretPassPhrase -P -md sha1 and copy key
    5. SESSION_SALT copy salt
    6. SESSION_IV copy iv
    7. JWT_ACCESSTOKEN_SECRET Run command openssl enc -aes-256-cbc -k MySuperSecretPassPhrase -P -md sha1 and copy key
    8. JWT_REFRESHTOKEN_SECRET Run command openssl enc -aes-256-cbc -k MySuperSecretPassPhrase -P -md sha1 and copy key
  16. Need to change below config in development.env file.

    1. MYSQL_HOST Change as per your dev server database
    2. MYSQL_PORT Change as per your dev server database
    3. MYSQL_USER Change as per your dev server database
    4. MYSQL_PASS Change as per your dev server database
    5. MYSQL_DBNAME Change database name
  17. Need to change below config in production.env file.

    1. MYSQL_HOST Change as per your prod server database
    2. MYSQL_PORT Change as per your prod server database
    3. MYSQL_USER Change as per your prod server database
    4. MYSQL_PASS Change as per your prod server database
    5. MYSQL_DBNAME Change database name
  18. Need to change below config in test.env file.

    1. MYSQL_HOST Change as per your local server database
    2. MYSQL_PORT Change as per your local server database
    3. MYSQL_USER Change as per your local server database
    4. MYSQL_PASS Change as per your local server database
    5. MYSQL_DBNAME Change database name
  19. Clean up /log/pino/test/*
  20. Clean up /log/pino/development/*
  21. Clean up /log/pino/production/*
  22. Run npm run start:debug:sharedapp
  23. Run npm run start:debug:app

Project setup on .dev server

  1. Create new database on .dev
  2. Update database connection in development.env file
  3. Go to .dev public_html
  4. Duplicate project_repo.zip
  5. Go to cicd on .one server and go to project repo
  6. Switch to dev branch and copy clone path ssh://git@cicd.thatsend.one:8222/source-code/api/your.project.repo.git
  7. Now, connect .dev server from SSH and go to your repo project root directory project.com.api. There are subfolder inside so do not get confused.
  8. Make sure you do not go inside any folder, must be on root of you project folder
  9. Now run below command, we will clone from dev branch only as this repo will be used for development. Creating multiple branch can use storage space.
  10. git clone -b dev ssh://git@cicd.thatsend.one:8222/source-code/api/your.project.repo.git
  11. So, if we follow the instruction fot this project clone command is git clone -b dev ssh://git@cicd.thatsend.one:8222/source-code/api/uklix.com_api.git
  12. Once cloned you will see a new folder created. Here you can rename this folder to repo for shorten name or leave it as it is.
  13. we genereally rename the folder as it comes with default name on cicd server
  14. as project is on .dev server we can start with project related process

nodeJS based project setup

  1. Make sure your server has nvm node npm installed and you have right version of node. BEfore you proceed further check this environemnt and make it availabe for your project.
  2. If you required installation go to official site or nvm and node
  3. Setup .env folder on your project repo root. You will find env folder in docs/gitignore
  4. Now run ~ npm i
  5. check any vulnerabilities, if any important then ~ npm audit fix or any other and make sure all packages are okay
  6. Time to setup cicd pipeline if not set. You need to update .gitlab-ci.yml file. Do required chnages and push and merge your changes
  7. This is important because when you will start work with some setup you might face some issue where you need to debug, so changing in file and check output become complex, with cicd it's become easy like you are working on your local environment
  8. Now, there are total 3 microservices need to start one by one. Order is important
    1. npm run start:dev:sharedapp
    2. npm run start:dev:businessapp
    3. npm run start:dev:app
  9. If you get error debug and fix, it might be some small issue as environment change
  10. Once service start it will show up in http://localhost:4000
  11. If your project domin is configured with reverce proxy you can access it from https://your-domin.com
  12. There are multiple way of reverse proxi setup, using .htacess and form virtual host. Use your suitable method.

Project setup on .dev.client server

Project setup on .production (main domain) server

Create Crud Module from existing module

  1. Copy any existing module which is similar as the module you want to create
  2. Rename folder as module-name For example, your tables name is user_corporate_info then your moudle folder name is user-corporate-info
  3. Rename all below files as module.name

    1. dto/user.corporate.info.dto.ts
    2. entity/user.corporate.info.entity.ts
    3. user.corporate.info.resolver.ts
    4. user.corporate.info.crud.factory.ts
    5. user.corporate.info.service.ts
    6. user.corporate.info.module.ts
  4. Now, open all files and remove unwanted contents for ex: foregin key relations or any other imported module which is not required in this module
  5. Now, we need to replace all required contents from all the files
  6. Follow below steps for all the files. Use Find and replace for all files with Match case enabled

    1. Search [user/.] and replace with [user.corporte.info/.]
    2. Search [user] and replace with [usercorporateinfo]
    3. Search [User] and replace with [UserCorporateInfo]
  7. Now, start to change entity and dto file.
  8. Below is the document refrences to create Entity field and grahql field

    1. https://docs.nestjs.com/techniques/graphql
    2. https://docs.nestjs.com/graphql/quick-start
    3. https://typeorm.io/entities
    4. https://the-guild.dev/graphql/scalars/docs
  9. First, start work with entity file

    1. Change [columnPrefix] as per the field prefix
    2. Copy all fields from the database tabel and set in commented code
    3. Remove column prefix from `[columnPrefix] to none
    4. Remove `, to ?: any;
    5. Find and replace manully for the above 3rd and 4th point
    6. change in const [Module.name]EntityFieldMeta set desc and validation as per the table columns
    7. Make sure the entity name means table name has changed properly if not then change as per database table name
    8. Change in [Module.name]Entity class as per the requirement of table fields
    9. Now, start to change dto file. Follow below steps

      1. Change 2 file names in comment ['../entities/user.entity', './dto/user.dto'] . perform find replce generally
      2. When you change file path, make sure you do not break some dependences which required this class, by find and replce path this is common issue this need to handle manually
      3. Go to defination [FindInputDtoCRUDTypeDefinition], just search and you will be there. Set field list as per new module entity class.
      4. Go to defination [FindInputWhereCRUDTypeDefinition], just search and you will be there. Set field list as per new module entity class.
      5. Go to defination [FindInputSortOrderCRUDTypeDefinition], just search and you will be there. Set field list as per new module entity class.
      6. Go to defination [FindInputGroupByCRUDTypeDefinition], just search and you will be there. Set field list as per new module entity class.
      7. Go to defination [FindOutputRowsCRUDTypeDefinition], just search and you will be there. By default this will inhereate ENTITY and if you need change, just set field list as per new module entity class.
      8. Go to defination [FindOutputCRUDTypeDefinition], just search and you will be there. Set field list as per new module entity class.
      9. Go to defination [CreateInputCRUDTypeDefinition], just search and you will be there. Set field list as per new module entity class.
      10. Go to defination [conflictResolveFields], need to change in code line { static conflictResolveFields: (keyof ApiEndpointAuthUpsertInput)[] = ['CHANGE_FIELD(S)']; }
      11. Make sure [FindOutputPagination] is imported from '@libs/library-app' (real location: /libs/library-app/src/crud/dto/standard/crud.pagination.dto)
  10. Now, Finally setup the Foregn key relations. Below is the TypeORm relations URL. https://typeorm.io/relations
  11. You can take reference from the folk/user/entities/user.entity.ts and folk/user-corporate-info/entities/user.corporate.info.entity.ts
  12. Below is the example
  13. ex: if one user has multiple corporate info, then you need to set the Many to Onerelation in user.corporate.info.entity.ts file and set the One to Many relation in user.entity.ts
  14. Many to One: @Field(() => UserEntity, {nullable: true, description: meta.fk_user.desc}) @ManyToOne(() => UserEntity, (entity: UserEntity) => entity.fk_user_corporate_infos) @JoinColumn({ name: `${columnPrefix}u_id` }) fk_user?: UserEntity;
  15. One to Many: @Field(() => [UserCorporateInfoEntity], {nullable: true, description: meta.fk_user_corporate_infos.desc}) @OneToMany(() => UserCorporateInfoEntity, (entity: UserCorporateInfoEntity) => entity.fk_user) fk_user_corporate_infos?: UserCorporateInfoEntity[]
  1. https://www.youtube.com/watch?v=0n2V5VF2wfY
  2. https://www.youtube.com/watch?v=i1wN86rnMEI&list=PLIGDNOJWiL1_YrquGbDDN4BNNRy678Spr