-
Notifications
You must be signed in to change notification settings - Fork 0
Food manufacturer dashboard #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6cedd26
8bf822b
4d8f66a
4bb76ac
79dc2b4
5058e5c
d70f582
47eff9c
ea97570
c70a1cd
93414f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,18 @@ export class DonationsController { | |
| return this.donationService.findOne(donationId); | ||
| } | ||
|
|
||
| @Get('/get-all-donations') | ||
| async getAllDonations(): Promise<Donation[]> { | ||
| return this.donationService.getAll(); | ||
| } | ||
|
|
||
| @Get('/getManufacturerDonationCount/:manufacturerId') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we update this to |
||
| async getManufacturerDonationCount( | ||
| @Param('manufacturerId', ParseIntPipe) manufacturerId: number, | ||
| ): Promise<number> { | ||
| return this.donationService.getManufacturerDonationCount(manufacturerId); | ||
| } | ||
|
|
||
| @Post('/create') | ||
| @ApiBody({ | ||
| description: 'Details for creating a donation', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,13 @@ export class DonationService { | |
| return this.repo.count(); | ||
| } | ||
|
|
||
| async getManufacturerDonationCount(manufacturerId: number) { | ||
| const count = await this.repo.count({ | ||
| where: { foodManufacturerId: manufacturerId }, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to be updated to reflect the entity changes |
||
| }); | ||
| return count; | ||
| } | ||
|
|
||
| async create( | ||
| foodManufacturerId: number, | ||
| dateDonated: Date, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { Controller, Get, Param, ParseIntPipe, Patch } from '@nestjs/common'; | ||
| import { FoodManufacturer } from './manufacturer.entity'; | ||
| import { ManufacturerService } from './manufacturer.service'; | ||
|
|
||
| @Controller('manufacturer') | ||
| export class ManufacturerController { | ||
| constructor(private manufacturerService: ManufacturerService) {} | ||
|
|
||
| @Get('/getDetails/:manufacturerId') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we change this to |
||
| async getManufacturerDetails( | ||
| @Param('manufacturerId', ParseIntPipe) manufacturerId: number, | ||
| ): Promise<FoodManufacturer | null> { | ||
| return this.manufacturerService.getDetails(manufacturerId); | ||
| } | ||
|
|
||
| @Patch('/updateFrequency/:manufacturerId/:frequency') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we also swap id and update frequency in the route here too |
||
| async updateManufacturerFrequency( | ||
| @Param('manufacturerId') manufacturerId: number, | ||
| @Param('frequency') frequency: string, | ||
| ): Promise<FoodManufacturer | null> { | ||
| return this.manufacturerService.updateManufacturerFrequency( | ||
| manufacturerId, | ||
| frequency, | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { TypeOrmModule } from '@nestjs/typeorm'; | ||
| import { FoodManufacturer } from './manufacturer.entity'; | ||
| import { ManufacturerController } from './manufacturer.controller'; | ||
| import { ManufacturerService } from './manufacturer.service'; | ||
| import { JwtStrategy } from '../auth/jwt.strategy'; | ||
| import { AuthService } from '../auth/auth.service'; | ||
|
|
||
| @Module({ | ||
| imports: [TypeOrmModule.forFeature([FoodManufacturer])], | ||
| controllers: [ManufacturerController], | ||
| providers: [ManufacturerService, AuthService, JwtStrategy], | ||
| }) | ||
| export class ManufacturerModule {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { Injectable, NotFoundException } from '@nestjs/common'; | ||
| import { InjectRepository } from '@nestjs/typeorm'; | ||
| import { Repository } from 'typeorm'; | ||
| import { FoodManufacturer } from './manufacturer.entity'; | ||
|
|
||
| @Injectable() | ||
| export class ManufacturerService { | ||
| constructor( | ||
| @InjectRepository(FoodManufacturer) | ||
| private repo: Repository<FoodManufacturer>, | ||
| ) {} | ||
|
|
||
| async updateManufacturerFrequency( | ||
| manufacturerId: number, | ||
| donationFrequency: string, | ||
| ): Promise<FoodManufacturer | null> { | ||
| const manufacturer = await this.repo.findOne({ | ||
| where: { foodManufacturerId: manufacturerId }, | ||
| }); | ||
| if (!manufacturer) { | ||
| return null; | ||
| } | ||
| manufacturer.donationFrequency = donationFrequency; | ||
| return this.repo.save(manufacturer); | ||
| } | ||
|
|
||
| async getDetails(manufacturerId: number): Promise<FoodManufacturer | null> { | ||
| if (!manufacturerId || manufacturerId < 1) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use validate id here |
||
| throw new NotFoundException('Invalid manufacturer ID'); | ||
| } | ||
| return await this.repo.findOne({ | ||
| where: { foodManufacturerId: manufacturerId }, | ||
| relations: ['foodManufacturerRepresentative'], | ||
| select: { | ||
| foodManufacturerId: true, | ||
| foodManufacturerName: true, | ||
| industry: true, | ||
| email: true, | ||
| phone: true, | ||
| address: true, | ||
| signupDate: true, | ||
| donationFrequency: true, | ||
| foodManufacturerRepresentative: { | ||
| firstName: true, | ||
| lastName: true, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class AddManufacturerDetails1743518493960 implements MigrationInterface { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| ALTER TABLE food_manufacturers | ||
| ADD COLUMN industry VARCHAR(255), | ||
| ADD COLUMN email VARCHAR(255), | ||
| ADD COLUMN phone VARCHAR(255), | ||
| ADD COLUMN address VARCHAR(255), | ||
| ADD COLUMN signup_date TIMESTAMP NOT NULL DEFAULT NOW(); | ||
| `); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| ALTER TABLE food_manufacturers | ||
| DROP COLUMN industry, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add IF EXISTS to these just in case |
||
| DROP COLUMN email, | ||
| DROP COLUMN phone, | ||
| DROP COLUMN address, | ||
| DROP COLUMN signup_date; | ||
| `); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class AddManufacturerDonationFrequency1743623272909 | ||
| implements MigrationInterface | ||
| { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| ALTER TABLE food_manufacturers | ||
| ADD COLUMN donation_frequency VARCHAR(255); | ||
| `); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| ALTER TABLE food_manufacturers | ||
| DROP COLUMN donation_frequency; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IF EXISTS here too |
||
| `); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have a
getAllDonations