An npm packages for common backend logic between client and dashboard app.
- Run
npm install @runnerpro/backend
Connection with the PostgresSQL database
- Param: string with PostgreSQL query
- Param: array of values
- Return: promise of array of values (each item is a row of the table)
Connection with PostgreSQL database in batches. Use for faster query execution when we need to execute many queries.
-
Param: Array of queries
- query: string with PostgreSQL query
- values: array of values
- Param?: length of promises wait together. Default 5
- Return: promise (without values)
Send mail with company logo and template
-
Param: { subject, title, body, to, link?, attachments?, bcc? }
- subject: title of the mail
- body: text inside card
- to: array of mails. In DEV and SBX the value is taken from .env GMAIL_EMAIL_USER
- link: button to redirect to the app. { text: text inside button, url: path (after runnerpro.com) }
- attachments: array of files to attach. { filename: name and extension of file, path: path of file, cid?: identifier to insert inside the body (
<img src="cid:__cid__" />
) } - bcc: array of mails to send via bcc
-
Return: promise (without values)
Send web or native notification to client: TODO
- Param: Array of queries { query: string with PostgreSQL query, values: array of values }
- Param?: length of promises wait together. Default 5
- Return: promise (without values)
Wait X miliseconds to execute next line
- Param: number of miliseconds of the promise
- Return: promise (without values)
- Create a folder with the name of functionality and index.ts inside. Write the function and export it.
- In main index.ts (the one inside src), import and export it
- Change the version number of the package (using this convenction)
- Run
npm login
- Run
npm run publish
- Install developer dependencies using the following command in your terminal
npm i -D mocha @types/mocha chai @types/chai ts-node
- Create a new file
.mocharc.json
in the root directory with the following contents:{ "extension": ["ts"], "spec": "./**/*.spec.ts", "require": "ts-node/register" }
- Create a
tests
folder - Create an
index.spec.ts
file in thetests
folder - Write unit tests in the
index.spec.ts
file to test the code inindex.ts
- Add a
"test"
property in thepackage.json
file and give it a value of"mocha"
- Run
npm test
in your terminal from the root folder of the project