Skip to content

Commit

Permalink
Merge branch 'acceptance' of github.com:Stichting-CROW/fietsberaad-ve…
Browse files Browse the repository at this point in the history
…iligstallen-app into acceptance

# Conflicts:
#	src/pages/api/auth/[...nextauth].ts
  • Loading branch information
bartwr committed Apr 4, 2024
2 parents 0c19062 + 8ca3b0b commit 6b3803c
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 101 deletions.
28 changes: 28 additions & 0 deletions mysql-db/handy-queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
select UserID FROM security_users where UserName="[email protected]" into @marc;
select ID From fietsenstallingen where Title like "%Marktstraat%" AND Plaats="Apeldoorn" INTO @stalling;
select @marc, @stalling;
INSERT INTO security_users_sites(UserID, SiteID, isContact) VALUES(@marc, @stalling, 0);

select fs.title
from security_users_sites sus
JOIN fietsenstallingen fs ON (fs.ID=sus.SiteID)
where sus.UserID=@marc;

Select * from fietsenstallingen_services where FietsenstallingID="0066B68F-6F95-4C42-BACF7B44C50FA061";
Select * from fietsenstallingen where ID="0066B68F-6F95-4C42-BACF7B44C50FA061";

select ID, Title, Beheerder, BeheerderContact, Capacity from fietsenstallingen WHERE IsStationsstalling;
select * from fietsenstallingen WHERE ID="0066B68F-6F95-4C42-BACF7B44C50FA061";

select * from security_users_sites where UserID="D4351342-685D-D17A-B3617EEBBF39451C";
select * from security_users_sites where UserID = @marc;

select * from fietsenstalling_sectie where fietsenstallingsId=@SiteID;

select fs.ID, fs.Title, fs.Plaats, fs.Capacity, count(fss.sectieId), sum(fss.capaciteit)
from fietsenstalling_sectie fss
left join fietsenstallingen fs ON fs.id=fss.fietsenstallingsId
WHERE fs.ID="0066B68F-6F95-4C42-BACF7B44C50FA061"
group by fs.ID
having count(fss.sectieId)>1
order by fs.Plaats, fs.Title
66 changes: 33 additions & 33 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
binaryTargets = ["native", "linux-musl-openssl-3.0.x", "debian-openssl-3.0.x"]
}

datasource db {
Expand Down Expand Up @@ -2027,46 +2027,46 @@ enum accounts_account_type {
// }

model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}

model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
@@unique([identifier, token])
}
32 changes: 30 additions & 2 deletions src/backend/services/fietsenstallingen-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,41 @@ import { prisma } from "~/server/db";
import type { fietsenstallingen } from "@prisma/client";
import type { ICrudService } from "~/backend/handlers/crud-service-interface";

BigInt.prototype.toJSON = function () {
const int = Number.parseInt(this.toString());
return int ?? this.toString();
};

const include = {
fietsenstalling_secties: {
include: {
secties_fietstype: {
include: { fietstype: true }
}
}
},
fietsenstallingen_services: {
include: {
services: true
}
}
}

// inspired by https://medium.com/@brandonlostboy/build-it-better-next-js-crud-api-b45d2e923896
const FietsenstallingenService: ICrudService<fietsenstallingen> = {
getAll: async () => {
return await prisma.fietsenstallingen.findMany();
return await prisma.fietsenstallingen.findMany({
include: {
fietsenstalling_secties: true,
}
});
},
getOne: async (id: string) => {
return await prisma.fietsenstallingen.findFirst({ where: { ID: id } });
return await prisma.fietsenstallingen.findFirst({
where: { ID: id },
include
}
);
},
create: async (_data: fietsenstallingen): Promise<fietsenstallingen> => {
return await prisma.fietsenstallingen.create({ data: _data });
Expand Down
8 changes: 5 additions & 3 deletions src/backend/services/fietsenstallingen_services-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ const FietsenstallingenServicesService: ICrudService<fietsenstallingen_services>
return await prisma.fietsenstallingen_services.findMany();
},
getOne: async (fietsenstallingId: string) => {
return await prisma.fietsenstallingen_services.findFirst({ where: {
FietsenstallingID: fietsenstallingId
} });
return await prisma.fietsenstallingen_services.findFirst({
where: {
FietsenstallingID: fietsenstallingId
}
});
},
create: async (_data: fietsenstallingen_services): Promise<fietsenstallingen_services> => {
return await prisma.fietsenstallingen_services.create({ data: _data });
Expand Down
19 changes: 12 additions & 7 deletions src/components/parking/ParkingEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { Tabs, Tab, FormHelperText, Typography } from "@mui/material";

/* Use nicely formatted items for items that can not be changed yet */
import ParkingViewTarief from "~/components/parking/ParkingViewTarief";
import type { ServiceType } from "~/components/parking/ParkingViewServices";

import ParkingViewAbonnementen from "~/components/parking/ParkingViewAbonnementen";
import ParkingEditCapaciteit, { type CapaciteitType } from "~/components/parking/ParkingEditCapaciteit";
import ParkingEditLocation from "~/components/parking/ParkingEditLocation";
Expand All @@ -36,8 +38,8 @@ export type ParkingEditUpdateStructure = {
Postcode?: string;
Plaats?: string;
Coordinaten?: string;
DateCreated: Date;
DateModified: Date;
DateCreated?: Date;
DateModified?: Date;
Type?: string;
SiteID?: string;
Beheerder?: string,
Expand All @@ -48,7 +50,6 @@ export type ParkingEditUpdateStructure = {
fietsenstalling_secties?: ParkingSections; // Replace with the actual type if different
}

type ServiceType = { ID: string, Name: string };
type ChangedType = { ID: string, selected: boolean };

const NoClickOverlay = () => {
Expand Down Expand Up @@ -237,11 +238,11 @@ const ParkingEdit = ({ parkingdata, onClose, onChange }: { parkingdata: ParkingD
let checks: checkInfo[] = [
{ type: "string", text: "invoer van de titel", value: parkingdata.Title, newvalue: newTitle },
{ type: "string", text: "invoer van de straat en huisnummer", value: parkingdata.Location, newvalue: newLocation },
{ type: "string", text: "invoer van de postcode", value: parkingdata.Postcode, newvalue: newPostcode },
{ type: "string", text: "invoer van de plaats", value: parkingdata.Plaats, newvalue: newPlaats },
{ type: "string", text: "selectie van de gemeente", value: parkingdata.SiteID, newvalue: newSiteID },
{ type: "coordinaten", text: "instellen van de locatie op de kaart", value: parkingdata.Coordinaten, newvalue: newCoordinaten },
]
// parkingdata.Postcode is optional

// FMS & ExploitantID cannot be changed for now, so no need to check those for changes
if (parkingdata.FMS !== true && parkingdata.ExploitantID === null) {
Expand Down Expand Up @@ -311,6 +312,7 @@ const ParkingEdit = ({ parkingdata, onClose, onChange }: { parkingdata: ParkingD
if (!parkingdata.DateCreated) {
update.DateCreated = today;
}

update.DateModified = today;

return update;
Expand Down Expand Up @@ -363,6 +365,7 @@ const ParkingEdit = ({ parkingdata, onClose, onChange }: { parkingdata: ParkingD
}

const updateCapaciteit = async (parkingdata: ParkingDetailsType, newCapaciteit: ParkingSections) => {
console.log("update capaciteit", newCapaciteit);
if (!newCapaciteit || newCapaciteit.length <= 0) return;

try {
Expand Down Expand Up @@ -541,8 +544,10 @@ const ParkingEdit = ({ parkingdata, onClose, onChange }: { parkingdata: ParkingD
return;
}


const method = isNew ? "POST" : "PUT";
const body = JSON.stringify(isNew ? Object.assign({}, parkingdata, update) : update);
console.log("update %s / %s", isNew, method, update);

const result = await fetch(
"/api/fietsenstallingen?id=" + parkingdata.ID,
Expand All @@ -564,9 +569,9 @@ const ParkingEdit = ({ parkingdata, onClose, onChange }: { parkingdata: ParkingD
}

// If capaciteit is updated: Update capaciteit
if (newCapaciteit && newCapaciteit.length > 0) {
await updateCapaciteit(parkingdata, newCapaciteit);
}
// if (newCapaciteit && newCapaciteit.length > 0) {
// await updateCapaciteit(parkingdata, newCapaciteit);
// }

let returnID: string | boolean = parkingdata.ID
if (session === null) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/parking/ParkingEditCapaciteit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ const toggleActive = (fietsenstalling_secties: ParkingSections, fietstypeName: s

const handleCapacityChange = (fietsenstalling_secties: ParkingSections, fietstypeName: any, amountstr: string): ParkingSections => {
// It's mandatory to have at least 1 section
if (!fietsenstalling_secties) return fietsenstalling_secties;
if (!fietsenstalling_secties) {
return fietsenstalling_secties;
}
if (!fietsenstalling_secties[0]) return fietsenstalling_secties;
if (!fietsenstalling_secties[0].secties_fietstype) return fietsenstalling_secties;

Expand Down
6 changes: 3 additions & 3 deletions src/components/parking/ParkingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const ParkingView = ({
<ParkingViewAbonnementen parkingdata={parkingdata} />

<SectionBlock heading="Soort stalling">
{parkingdata.fietsenstalling_type?.name || "Onbekend"}
{parkingdata.Type || "Onbekend"}
</SectionBlock>

<HorizontalDivider className="my-4" />
Expand All @@ -141,7 +141,7 @@ const ParkingView = ({
sm:absolute
sm:bottom-1
"
onClick={(e) => {
onClick={(e: any) => {
if (e) e.preventDefault();
openRoute(parkingdata.Coordinaten);
}}
Expand All @@ -158,7 +158,7 @@ const ParkingView = ({
</div>
</div>

</div>
</div >
);
};

Expand Down
26 changes: 18 additions & 8 deletions src/components/parking/ParkingViewBeheerder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@ import HorizontalDivider from "~/components/HorizontalDivider";
import SectionBlock from "~/components/SectionBlock";

const ParkingViewBeheerder = ({ parkingdata }: { parkingdata: any }) => {
// console.log("### ParkingViewBeheerder", parkingdata, parkingdata.Exploitant, parkingdata.Beheerder, parkingdata.BeheerderContact);
if (parkingdata.FMS === true) {
return <SectionBlock heading="Beheerder">FMS</SectionBlock>;
} else if(parkingdata?.exploitant) {
console.log("### ParkingViewBeheerder", parkingdata, parkingdata.Exploitant, parkingdata.Beheerder, parkingdata.BeheerderContact);
// if (parkingdata.FMS === true) {
// return <SectionBlock heading="Beheerder">FMS</SectionBlock>;
// } else
if (parkingdata?.exploitant) {
return (
<SectionBlock heading="Beheerder">
<a href={'mailto:'+parkingdata.exploitant.Helpdesk}>{parkingdata.exploitant.CompanyName}</a>
<a href={'mailto:' + parkingdata.exploitant.Helpdesk}>{parkingdata.exploitant.CompanyName}</a>
</SectionBlock>
)
} else if(parkingdata.BeheerderContact !== null) {
} else if (parkingdata.BeheerderContact !== null) {
let contactlink = "";
if (parkingdata.BeheerderContact.includes("@")) {
contactlink = 'mailto:' + parkingdata.BeheerderContact
} else if (parkingdata.BeheerderContact.startsWith("http")) {
contactlink = parkingdata.BeheerderContact;
} else if (parkingdata.BeheerderContact.startsWith("www")) {
contactlink = 'https://' + parkingdata.BeheerderContact;
}

return (
<SectionBlock heading="Beheerder">
<a href={parkingdata.BeheerderContact}>{parkingdata.Beheerder === null ? 'contact' : parkingdata.Beheerder}</a>
<a href={contactlink}>{parkingdata.Beheerder === null ? parkingdata.BeheerderContact : parkingdata.Beheerder}</a>
</SectionBlock>
);
);
} else {
return null
}
Expand Down
21 changes: 15 additions & 6 deletions src/components/parking/ParkingViewCapaciteit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ const calculateCapacityData = (parking: ParkingDetailsType): capacitydata | null
detailed: {},
};

if (parking === null || parking.Capacity === 0) {
capacity.unknown = true;
if (parking === null) {
capacity.unknown = true
} else if (parking.fietsenstalling_secties.length === 0) {
capacity.unknown = false;
capacity.total = parking.Capacity || 0;
} else {
// Get parking section (new: 1 per parking, to make it easy)
parking.fietsenstalling_secties.forEach((sectie) => {
Expand All @@ -41,7 +44,7 @@ const calculateCapacityData = (parking: ParkingDetailsType): capacitydata | null
let detailed = capacity.detailed[name];
if (detailed !== undefined) {
detailed.Toegestaan = detailed.Toegestaan || (data.Toegestaan !== null && data.Toegestaan);
detailed.Capaciteit += detailed.Capaciteit || 0;
detailed.Capaciteit += data.Capaciteit || 0;
}
// capacity.detailed[name].Toegestaan = capacity.detailed[name].Toegestaan || data.Toegestaan !== null && data.Toegestaan;
// capacity.detailed[name].Capaciteit += data.Capaciteit || 0;
Expand All @@ -63,9 +66,11 @@ const ParkingViewCapaciteit = ({ parkingdata }: { parkingdata: ParkingDetailsTyp
const capacitydata = calculateCapacityData(parkingdata);
// console.log("#### capacitydata", capacitydata, parkingdata);

if (capacitydata === null || capacitydata?.unknown) {
content = "Onbekend";
} else if (capacitydata.detailed === null || Object.keys(capacitydata.detailed).length === 0) {
if (capacitydata === null || capacitydata?.unknown || (Object.keys(capacitydata.detailed).length === 0 && capacitydata.total === 0)) {
return null;
}

if (capacitydata.detailed === null || Object.keys(capacitydata.detailed).length === 0) {
content = (
<>
<div className="">{parkingdata.Capacity}</div>
Expand Down Expand Up @@ -98,6 +103,10 @@ const ParkingViewCapaciteit = ({ parkingdata }: { parkingdata: ParkingDetailsTyp
});
}

if (content === null) {
return null;
}

return (
<>
<SectionBlock heading="Capaciteit">
Expand Down
Loading

0 comments on commit 6b3803c

Please sign in to comment.