Jordi aquí tens el projecte finalitzat.
Per desenvolupar-ho, he assumit les següents presuncions al interpretar el teu full tècnic:
-
Només hi ha una taula chargepoint per al servei com a la db. Ja que name és "unique" només tindrem un registre a la taula per cada chargepoint, si entra un post o update de un chargepoint.name existent farem update del registre existent (state y created_at).
-
El registre d'un chargepoint no es borra si no que s'escriu la data de "delete_at" del registre del chargepoint llavor desapareix de les vistes però no de la db.
Finalment he inclós el desenvolupament per socket server (port 8060 localhost). Per testejar-ho obrir un terminal executar un client (o tants terminals com vulguis):
$ node ws-client.js ws-client.js és inclós al projecte.
Nestjs used to setup project and create Typeorm used as ORM. Migrations development avalaible. Package class-validator for validation Added swagger validation. Simple tests added, internal dependancies and general test api running.
Steps to execute the application.
Create or copy .env file:
Example: https://github.com/juanrogue/wenea-chargepoints/blob/main/.local.env%20
Load variables on env:
set -a # automatically export all variables
source .env
set +aYou will need a Postgre blank database to setup and run this project.
sudo -u postgres psql;
create database wenea;
create user wenea_user with encrypted password '54bgt123';
grant all privileges on database wenea to wenea_user;Once created the .env file and db install, build and run project. Database will be fulfilled with the created tables. Run migrations if necesaire.
$ npm installBuild:
$ npm run buildRun:
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:covPostman collection for fast testing avalaible at: https://github.com/juanrogue/wenea-chargepoints/blob/main/Webea.postman_collection.json
This is project is easy scalable. Used nestjs or typeorm for those purposes (migrations pipeline inc).
nest g resource entity_nameLocated at path: src/database/migrations
# To execute pending migrations, use the following command:
$ npm run migration:run
# migration generate
$ npm run migration:generate ./src/database/migrations/update-post-table