From f17ae44f995af5d505b0c0454a7e23dc9d3c190b Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Fri, 27 Dec 2024 09:13:48 +0000 Subject: [PATCH] TS-936 Municipality - Added municipality service --- .../screens/AccessControl/AccessControl.tsx | 2 + .../AccessControlImage/AccessControlImage.tsx | 84 --- .../screens/AccessControl/components/index.ts | 1 - .../AccessControlImage/AccessControlImage.tsx | 84 --- .../AccessControlCompany/components/index.ts | 1 - .../RecyclingCompanyForm.tsx | 25 +- .../RecyclingCompanyImage.tsx | 591 ------------------ .../RecyclingCompanyImage/index.tsx | 1 - .../RecyclingCompanies/components/index.ts | 1 - .../RecyclingCompanyImage.tsx | 591 ------------------ .../RecyclingCompanyImage/index.tsx | 1 - .../Overview/components/index.ts | 1 - apps/skilavottord/ws/src/app/app.module.ts | 16 +- apps/skilavottord/ws/src/app/modules/index.ts | 1 + .../ws/src/app/modules/municipality/index.ts | 1 + .../municipality/municipality.module.ts | 13 + .../municipality/municipality.resolver.ts | 22 + .../municipality/municipality.service.ts | 16 + 18 files changed, 80 insertions(+), 1372 deletions(-) delete mode 100644 apps/skilavottord/web/screens/AccessControl/components/AccessControlImage/AccessControlImage.tsx delete mode 100644 apps/skilavottord/web/screens/AccessControlCompany/components/AccessControlImage/AccessControlImage.tsx delete mode 100644 apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyImage/RecyclingCompanyImage.tsx delete mode 100644 apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyImage/index.tsx delete mode 100644 apps/skilavottord/web/screens/RecyclingFund/Overview/components/RecyclingCompanyImage/RecyclingCompanyImage.tsx delete mode 100644 apps/skilavottord/web/screens/RecyclingFund/Overview/components/RecyclingCompanyImage/index.tsx create mode 100644 apps/skilavottord/ws/src/app/modules/municipality/municipality.module.ts create mode 100644 apps/skilavottord/ws/src/app/modules/municipality/municipality.resolver.ts create mode 100644 apps/skilavottord/ws/src/app/modules/municipality/municipality.service.ts diff --git a/apps/skilavottord/web/screens/AccessControl/AccessControl.tsx b/apps/skilavottord/web/screens/AccessControl/AccessControl.tsx index e9ec6cf77ae6..5a19257ba006 100644 --- a/apps/skilavottord/web/screens/AccessControl/AccessControl.tsx +++ b/apps/skilavottord/web/screens/AccessControl/AccessControl.tsx @@ -241,6 +241,7 @@ const AccessControl: FC> = () => { : partner.companyName, value: partner.companyId, })) + .sort((a, b) => a.label.localeCompare(b.label)) const municipalities = filterInternalPartners(partners) .filter((partner) => { @@ -250,6 +251,7 @@ const AccessControl: FC> = () => { label: partner.companyName, value: partner.companyId, })) + .sort((a, b) => a.label.localeCompare(b.label)) const roles = Object.keys(AccessControlRole) .filter((role) => diff --git a/apps/skilavottord/web/screens/AccessControl/components/AccessControlImage/AccessControlImage.tsx b/apps/skilavottord/web/screens/AccessControl/components/AccessControlImage/AccessControlImage.tsx deleted file mode 100644 index eff24d85cd68..000000000000 --- a/apps/skilavottord/web/screens/AccessControl/components/AccessControlImage/AccessControlImage.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import React, { FC } from 'react' - -export const AccessControlImage: FC> = () => ( - - - - - - - - - - - - - - - - - - - - - - - - - -) diff --git a/apps/skilavottord/web/screens/AccessControl/components/index.ts b/apps/skilavottord/web/screens/AccessControl/components/index.ts index 8a2d7ea51249..6635d196186f 100644 --- a/apps/skilavottord/web/screens/AccessControl/components/index.ts +++ b/apps/skilavottord/web/screens/AccessControl/components/index.ts @@ -1,3 +1,2 @@ -export { AccessControlImage } from './AccessControlImage/AccessControlImage' export { AccessControlCreate } from './AccessControlCreate/AccessControlCreate' export { AccessControlUpdate } from './AccessControlUpdate/AccessControlUpdate' diff --git a/apps/skilavottord/web/screens/AccessControlCompany/components/AccessControlImage/AccessControlImage.tsx b/apps/skilavottord/web/screens/AccessControlCompany/components/AccessControlImage/AccessControlImage.tsx deleted file mode 100644 index eff24d85cd68..000000000000 --- a/apps/skilavottord/web/screens/AccessControlCompany/components/AccessControlImage/AccessControlImage.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import React, { FC } from 'react' - -export const AccessControlImage: FC> = () => ( - - - - - - - - - - - - - - - - - - - - - - - - - -) diff --git a/apps/skilavottord/web/screens/AccessControlCompany/components/index.ts b/apps/skilavottord/web/screens/AccessControlCompany/components/index.ts index 8a2d7ea51249..6635d196186f 100644 --- a/apps/skilavottord/web/screens/AccessControlCompany/components/index.ts +++ b/apps/skilavottord/web/screens/AccessControlCompany/components/index.ts @@ -1,3 +1,2 @@ -export { AccessControlImage } from './AccessControlImage/AccessControlImage' export { AccessControlCreate } from './AccessControlCreate/AccessControlCreate' export { AccessControlUpdate } from './AccessControlUpdate/AccessControlUpdate' diff --git a/apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyForm/RecyclingCompanyForm.tsx b/apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyForm/RecyclingCompanyForm.tsx index 0b7b260236ae..a3f79cd05825 100644 --- a/apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyForm/RecyclingCompanyForm.tsx +++ b/apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyForm/RecyclingCompanyForm.tsx @@ -4,7 +4,7 @@ import { Control, Controller, FieldError } from 'react-hook-form' import { FieldValues } from 'react-hook-form/dist/types' import { DeepMap } from 'react-hook-form/dist/types/utils' -import { useQuery } from '@apollo/client' +import { gql, useQuery } from '@apollo/client' import { Box, Button, @@ -23,7 +23,6 @@ import { import UserContext from '@island.is/skilavottord-web/context/UserContext' import { Query } from '@island.is/skilavottord-web/graphql/schema' import { useI18n } from '@island.is/skilavottord-web/i18n' -import { SkilavottordRecyclingPartnersQuery } from '../../RecyclingCompanies' interface RecyclingCompanyForm { onSubmit: ( @@ -36,6 +35,15 @@ interface RecyclingCompanyForm { isMunicipalityPage?: boolean | undefined } +export const SkilavottordAllMunicipalitiesQuery = gql` + query skilavottordAllMunicipalitiesQuery { + skilavottordAllMunicipalities { + companyId + companyName + } + } +` + const RecyclingCompanyForm: FC< React.PropsWithChildren > = ({ @@ -53,17 +61,16 @@ const RecyclingCompanyForm: FC< } = useI18n() const { data } = - useQuery(SkilavottordRecyclingPartnersQuery, { - skip: isMunicipalityPage, - variables: { isMunicipalityPage: true }, + useQuery(SkilavottordAllMunicipalitiesQuery, { + fetchPolicy: 'cache-and-network', }) || [] - const municipalities = data?.skilavottordRecyclingPartners.map( - (municipality) => ({ + const municipalities = data?.skilavottordAllMunicipalities + .map((municipality) => ({ label: municipality.companyName, value: municipality.companyId, - }), - ) + })) + .sort((a, b) => a.label.localeCompare(b.label)) return (
diff --git a/apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyImage/RecyclingCompanyImage.tsx b/apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyImage/RecyclingCompanyImage.tsx deleted file mode 100644 index b535ec6907c6..000000000000 --- a/apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyImage/RecyclingCompanyImage.tsx +++ /dev/null @@ -1,591 +0,0 @@ -import React from 'react' - -export default () => ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -) diff --git a/apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyImage/index.tsx b/apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyImage/index.tsx deleted file mode 100644 index dd5bae5ecc50..000000000000 --- a/apps/skilavottord/web/screens/RecyclingCompanies/components/RecyclingCompanyImage/index.tsx +++ /dev/null @@ -1 +0,0 @@ -export { default as RecyclingCompanyImage } from './RecyclingCompanyImage' diff --git a/apps/skilavottord/web/screens/RecyclingCompanies/components/index.ts b/apps/skilavottord/web/screens/RecyclingCompanies/components/index.ts index 03d8d876f7f0..3c6b797ce257 100644 --- a/apps/skilavottord/web/screens/RecyclingCompanies/components/index.ts +++ b/apps/skilavottord/web/screens/RecyclingCompanies/components/index.ts @@ -1,2 +1 @@ -export { RecyclingCompanyImage } from './RecyclingCompanyImage' export { RecyclingCompanyForm } from './RecyclingCompanyForm' diff --git a/apps/skilavottord/web/screens/RecyclingFund/Overview/components/RecyclingCompanyImage/RecyclingCompanyImage.tsx b/apps/skilavottord/web/screens/RecyclingFund/Overview/components/RecyclingCompanyImage/RecyclingCompanyImage.tsx deleted file mode 100644 index b535ec6907c6..000000000000 --- a/apps/skilavottord/web/screens/RecyclingFund/Overview/components/RecyclingCompanyImage/RecyclingCompanyImage.tsx +++ /dev/null @@ -1,591 +0,0 @@ -import React from 'react' - -export default () => ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -) diff --git a/apps/skilavottord/web/screens/RecyclingFund/Overview/components/RecyclingCompanyImage/index.tsx b/apps/skilavottord/web/screens/RecyclingFund/Overview/components/RecyclingCompanyImage/index.tsx deleted file mode 100644 index dd5bae5ecc50..000000000000 --- a/apps/skilavottord/web/screens/RecyclingFund/Overview/components/RecyclingCompanyImage/index.tsx +++ /dev/null @@ -1 +0,0 @@ -export { default as RecyclingCompanyImage } from './RecyclingCompanyImage' diff --git a/apps/skilavottord/web/screens/RecyclingFund/Overview/components/index.ts b/apps/skilavottord/web/screens/RecyclingFund/Overview/components/index.ts index 052f49f9b3bb..b34076c09fb2 100644 --- a/apps/skilavottord/web/screens/RecyclingFund/Overview/components/index.ts +++ b/apps/skilavottord/web/screens/RecyclingFund/Overview/components/index.ts @@ -1,2 +1 @@ -export { RecyclingCompanyImage } from './RecyclingCompanyImage' export { CarsTable } from './CarsTable' diff --git a/apps/skilavottord/ws/src/app/app.module.ts b/apps/skilavottord/ws/src/app/app.module.ts index 7f8d55a37ef5..0b0a3eab281d 100644 --- a/apps/skilavottord/ws/src/app/app.module.ts +++ b/apps/skilavottord/ws/src/app/app.module.ts @@ -1,24 +1,25 @@ -import { Module } from '@nestjs/common' import { ApolloDriver } from '@nestjs/apollo' +import { Module } from '@nestjs/common' import { GraphQLModule } from '@nestjs/graphql' import { SequelizeModule } from '@nestjs/sequelize' import { BASE_PATH } from '@island.is/skilavottord/consts' +import { AuthModule as AuthJwtModule } from '@island.is/auth-nest-tools' +import { environment } from '../environments' import { AccessControlModule, AuthModule, + FjarsyslaModule, GdprModule, - VehicleModule, - RecyclingRequestModule, + MunicipalityModule, RecyclingPartnerModule, - VehicleOwnerModule, + RecyclingRequestModule, SamgongustofaModule, - FjarsyslaModule, + VehicleModule, + VehicleOwnerModule, } from './modules' -import { AuthModule as AuthJwtModule } from '@island.is/auth-nest-tools' import { SequelizeConfigService } from './sequelizeConfig.service' -import { environment } from '../environments' const debug = process.env.NODE_ENV === 'development' const playground = debug || process.env.GQL_PLAYGROUND_ENABLED === 'true' @@ -51,6 +52,7 @@ const autoSchemaFile = environment.production RecyclingPartnerModule, VehicleModule, VehicleOwnerModule, + MunicipalityModule, ], }) export class AppModule {} diff --git a/apps/skilavottord/ws/src/app/modules/index.ts b/apps/skilavottord/ws/src/app/modules/index.ts index e4b1468e21b0..8becbef0fe93 100644 --- a/apps/skilavottord/ws/src/app/modules/index.ts +++ b/apps/skilavottord/ws/src/app/modules/index.ts @@ -7,3 +7,4 @@ export { RecyclingRequestModule } from './recyclingRequest/recyclingRequest.modu export { SamgongustofaModule } from './samgongustofa/samgongustofa.module' export { VehicleModule } from './vehicle/vehicle.module' export { VehicleOwnerModule } from './vehicleOwner/vehicleOwner.module' +export { MunicipalityModule } from './municipality/municipality.module' diff --git a/apps/skilavottord/ws/src/app/modules/municipality/index.ts b/apps/skilavottord/ws/src/app/modules/municipality/index.ts index e0633f1312d8..fe55d7539d2c 100644 --- a/apps/skilavottord/ws/src/app/modules/municipality/index.ts +++ b/apps/skilavottord/ws/src/app/modules/municipality/index.ts @@ -1 +1,2 @@ export { MunicipalityModel } from './municipality.model' +export { MunicipalityService } from './municipality.service' diff --git a/apps/skilavottord/ws/src/app/modules/municipality/municipality.module.ts b/apps/skilavottord/ws/src/app/modules/municipality/municipality.module.ts new file mode 100644 index 000000000000..bf7f93719f39 --- /dev/null +++ b/apps/skilavottord/ws/src/app/modules/municipality/municipality.module.ts @@ -0,0 +1,13 @@ +import { Module } from '@nestjs/common' +import { SequelizeModule } from '@nestjs/sequelize' + +import { MunicipalityModel } from './municipality.model' +import { MunicipalityResolver } from './municipality.resolver' +import { MunicipalityService } from './municipality.service' + +@Module({ + imports: [SequelizeModule.forFeature([MunicipalityModel])], + providers: [MunicipalityResolver, MunicipalityService], + exports: [MunicipalityService], +}) +export class MunicipalityModule {} diff --git a/apps/skilavottord/ws/src/app/modules/municipality/municipality.resolver.ts b/apps/skilavottord/ws/src/app/modules/municipality/municipality.resolver.ts new file mode 100644 index 000000000000..e33be348b5cc --- /dev/null +++ b/apps/skilavottord/ws/src/app/modules/municipality/municipality.resolver.ts @@ -0,0 +1,22 @@ +import { Query, Resolver } from '@nestjs/graphql' + +import { Authorize, Role } from '../auth' + +import { MunicipalityModel } from './municipality.model' +import { MunicipalityService } from './municipality.service' + +@Authorize() +@Resolver(() => MunicipalityModel) +export class MunicipalityResolver { + constructor(private municipalityService: MunicipalityService) {} + + @Authorize({ + roles: [Role.developer, Role.recyclingFund, Role.municipality], + }) + @Query(() => [MunicipalityModel], { + name: 'skilavottordAllMunicipalities', + }) + async skilavottordAllMunicipalities(): Promise { + return this.municipalityService.findAll() + } +} diff --git a/apps/skilavottord/ws/src/app/modules/municipality/municipality.service.ts b/apps/skilavottord/ws/src/app/modules/municipality/municipality.service.ts new file mode 100644 index 000000000000..35e3231a635d --- /dev/null +++ b/apps/skilavottord/ws/src/app/modules/municipality/municipality.service.ts @@ -0,0 +1,16 @@ +import { Injectable } from '@nestjs/common' +import { InjectModel } from '@nestjs/sequelize' + +import { MunicipalityModel } from './municipality.model' + +@Injectable() +export class MunicipalityService { + constructor( + @InjectModel(MunicipalityModel) + private municipalityModel: typeof MunicipalityModel, + ) {} + + async findAll(): Promise { + return await this.municipalityModel.findAll() + } +}