{"id":24598468,"url":"https://github.com/itobuztech/pharmastock-backend","last_synced_at":"2025-03-18T05:29:48.124Z","repository":{"id":273687031,"uuid":"920477290","full_name":"itobuztech/pharmastock-backend","owner":"itobuztech","description":"pharma stock with Nest JS, Graphql Node JS, PostgreSQL","archived":false,"fork":false,"pushed_at":"2025-01-22T10:53:44.000Z","size":492,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T11:34:12.046Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itobuztech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-22T08:13:58.000Z","updated_at":"2025-01-22T10:53:48.000Z","dependencies_parsed_at":"2025-01-22T11:44:31.050Z","dependency_job_id":null,"html_url":"https://github.com/itobuztech/pharmastock-backend","commit_stats":null,"previous_names":["itobuztech/pharmastock-backend"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itobuztech%2Fpharmastock-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itobuztech%2Fpharmastock-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itobuztech%2Fpharmastock-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itobuztech%2Fpharmastock-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itobuztech","download_url":"https://codeload.github.com/itobuztech/pharmastock-backend/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244164166,"owners_count":20408876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-24T12:16:34.013Z","updated_at":"2025-03-18T05:29:48.097Z","avatar_url":"https://github.com/itobuztech.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pharmacy Management System\n\n[![License](https://img.shields.io/github/license/saluki/nestjs-template.svg)](https://github.com/pgm-arthtemm/nestjs-auth-rbac-starter/blob/main/LICENSE)\n\nQuick starter template for a [NestJS](https://nestjs.com/) **GraphQL** API with **user authentication** and **role based access control**.  \nThis template uses:\n\n- GraphQL\n- Prisma\n- Postgres\n- Apollo Server\n- Passport-JWT\n\n### Frontend repo link:\n\nhttps://github.com/itobuztech/pharmastock-frontend\n\n## Setup\n\nStart by cloning the repository into your local workstation:\n\n```sh\ngit clone https://github.com/pgm-arthtemm/nestjs-auth-rbac-starter.git my-project\n```\n\nThis project is made with yarn. So use `yarn add`, not anything else.\n\n```sh\ncd ./my-project\nyarn install\n```\n\nCreate two `.env` files in the root of the project:\n\n- `.env.development`\n- `.env.production`\n\nIn the `.env.development` file, put the environment variables used in **development**.  \nThe `.env.production` file will contain all the environment variables for **production**.\n\nTo make connection with the database, fill in the right environment variables in the app.module.ts.\n\n## Usage\n\nWhen the database is connected, you can start up the server by running `yarn start:dev`.\nA GraphQL schema will be generated. This will contain a Users table and all the dto's for user authentication.\n\nTo register a user:\n\n- Go to the [GraphQL Playground](http://localhost:4000/graphql)\n- Run the signup mutation using `email`, `password` and `username` variables\n\nRunning this mutation will create a new entry in the Users table **if the email is not already registered**.\nThe default Role will be set as USER. you can change this by creating a new role in the `roles` table and changing the default role in the `create` method of the `users.service.ts` file.\n\n```js\nconst defaultRole = await this.prisma.role.findFirst({\n  select: {\n    id: true,\n  },\n});\n```\n\nTo login a user:\n\n- Go to the [GraphQL Playground](http://localhost:4000/graphql)\n- Run the login mutation using `email` and `password` variables\n\nRunning this mutation will check the credentials of the user, if the credentials are correct, the mutation will return a JWT.\nThis token contains the user information, including the user role.\n\n## Jwt Guards\n\nTo protect an API route, you can use a **JwtGuard**. This guard checks if the user has a valid JWT. You can apply this guard to the **UseGuard decorator** to queries and mutations inside a resolver.\nIn this example the findAll users query inside the `users.resolver.ts` file is protected using this guard.\n\n```js\n  @Query(() =\u003e [User], { name: 'users' })\n  @UseGuards(JwtAuthGuard)\n  findAll(): Promise\u003cUser[]\u003e {\n    return this.usersService.findAll();\n  }\n```\n\nTo send an authenticated request in the GraphQL playground, you can use the JWT that was returned after loggin in.\nAdd this to the HTTP Headers.  \n**Remove the \"\u003c\u003e\"**.\n\n```json\n{\n  \"Authorization\": \"Bearer \u003cyour token\u003e\"\n}\n```\n\n## Role Guards\n\nThe protect an API route from a specific user Role, you can use a **Roles** guard. This guard checks if the user has the correct roles to access the specified route.\nIn this example the findAll users query inside the `users.resolver.ts` file is protected using this guard.  \nOnly a user with the OWNER role can access this endpoint.\n\n```js\n  @Query(() =\u003e [User], { name: 'users' })\n  @UseGuards(JwtAuthGuard, RolesGuard)\n  @Roles(UserRoles.OWNER)\n  findAll(): Promise\u003cUser[]\u003e {\n    return this.usersService.findAll();\n  }\n```\n\n## Permissions Guards\n\nThe protect an API route from a specific user Permission, you can use a **PermissionsAND** or **PermissionsOR** guard. These guards check if the user has the correct privilege to access the specified resolver.\n\n```js\n  @Query(() =\u003e User, { name: 'account' })\n  @UseGuards(JwtAuthGuard, PermissionsGuardOR)\n  @Permissions([PrivilegesList.PROFILE.CAPABILITIES.VIEW])\n  findOne(@Context() ctx: any): Promise\u003cUser\u003e {\n    return this.accountService.findOne();\n  }\n```\n\n## E2E Tests:\n\nYou need to have `dotenv` installed globally. Create a separate database for testing and update in the **.env.test** accordingly.\nRun `dotenv -e .env.test -- npx prisma migrate dev` and `dotenv -e .env.test -- npx prisma db seed` to create the tables and populate the test database. Run migrations using `yarn run test:e2e`.\n\n## DEMO URL AND CREDENTIAL:\n\nhttps://pharmastock.x-studio.io/login\n\n### Admin Credential\n\n```\nEmail = sudeepAdmin.healthfirst@itobuz.com\nPassword = Itobuz#1234\n```\n\n### Staff Credential\n\n```\nEmail = aliceStaff.healthfirst@itobuz.com\nPassword = Itobuz#1234\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitobuztech%2Fpharmastock-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitobuztech%2Fpharmastock-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitobuztech%2Fpharmastock-backend/lists"}