Skip to content

Commit

Permalink
feat(interfaces): Add enums.ts to @codeanker/interfaces package
Browse files Browse the repository at this point in the history
Add the enums.ts file to the @codeanker/interfaces package, which exports the Countries enum.
  • Loading branch information
danielswiatek committed Sep 7, 2024
1 parent 6edb81f commit 28355e6
Show file tree
Hide file tree
Showing 26 changed files with 2,903 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
"options": {
"cwd": "${workspaceFolder}/api",
"statusbar": {
"hide" : true
"hide" : false
}
},
"presentation": {
Expand Down
3 changes: 3 additions & 0 deletions api/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"meilisearch": {
"host": "MEILISEARCH_HOST",
"apiKey": "MEILISEARCH_KEY"
},
"tomtom": {
"apiKey": "TOMTOM_APIKEY"
}
}
2 changes: 2 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "tsx watch --clear-screen=false --env-file .env src/server.ts",
"createAccount": "tsx src/scripts/createAccount.ts",
"initMeilisearch": "tsx src/scripts/initMeilisearch.ts",
"cli": "tsx src/cli/index.ts",
"postinstall": "prisma generate"
},
"exports": {
Expand All @@ -30,6 +31,7 @@
"@prisma/extension-accelerate": "^0.6.3",
"@sendgrid/mail": "^8.1.0",
"@trpc/server": "^10.28.1",
"axios": "^1.7.7",
"config": "^3.3.9",
"dayjs": "^1.11.10",
"fast-csv": "^5.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- You are about to drop the column `number` on the `Address` table. All the data in the column will be lost.
- Added the required column `streetNumber` to the `Address` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Address" DROP COLUMN "number",
ADD COLUMN "lat" TEXT,
ADD COLUMN "lon" TEXT,
ADD COLUMN "streetNumber" TEXT NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:
- Added the required column `country` to the `Address` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Address" ADD COLUMN "country" TEXT NOT NULL,
ADD COLUMN "valid" BOOLEAN NOT NULL DEFAULT false;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- The `lat` column on the `Address` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The `lon` column on the `Address` table would be dropped and recreated. This will lead to data loss if there is data in the column.
*/
-- AlterTable
ALTER TABLE "Address" DROP COLUMN "lat",
ADD COLUMN "lat" DOUBLE PRECISION,
DROP COLUMN "lon",
ADD COLUMN "lon" DOUBLE PRECISION;
126 changes: 65 additions & 61 deletions api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch"]
}

Expand Down Expand Up @@ -112,17 +112,17 @@ enum Konfektionsgroesse {
}

model Hostname {
id Int @id @default(autoincrement())
hostname String
id Int @id @default(autoincrement())
hostname String
veranstaltung Veranstaltung[]
}

model Notfallkontakt {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
firstname String
lastname String
telefon String
istErziehungsberechtigt Boolean @default(false)
istErziehungsberechtigt Boolean @default(false)
personId Int
person Person @relation(fields: [personId], references: [id], onDelete: Cascade)
}
Expand Down Expand Up @@ -157,7 +157,7 @@ model Person {
model Account {
id Int @id @default(autoincrement())
email String @unique
dlrgOauthId String? @unique
dlrgOauthId String? @unique
password String?
role Role
personId Int @unique
Expand Down Expand Up @@ -220,13 +220,17 @@ model Anmeldung {
}

model Address {
id Int @id @default(autoincrement())
street String
number String
zip String
city String
Ort Ort[]
Person Person[]
id Int @id @default(autoincrement())
street String
streetNumber String
zip String
city String
country String
lat Float?
lon Float?
valid Boolean @default(false)
Ort Ort[]
Person Person[]
}

model Ort {
Expand All @@ -238,26 +242,26 @@ model Ort {
}

model Veranstaltung {
id Int @id @default(autoincrement())
name String
beginn DateTime @db.Date
ende DateTime @db.Date
meldebeginn DateTime
meldeschluss DateTime
ortId Int?
ort Ort? @relation(fields: [ortId], references: [id], onDelete: SetNull)
maxTeilnehmende Int
teilnahmegebuehr Int
unterveranstaltungen Unterveranstaltung[]
mahlzeiten Mahlzeit[]
beschreibung String?
datenschutz String?
teilnahmeBedingungen String?
teilnahmeBedingungenPublic String?
zielgruppe String?
hostnameId Int?
hostname Hostname? @relation(fields: [hostnameId], references: [id])
customFields CustomField[]
id Int @id @default(autoincrement())
name String
beginn DateTime @db.Date
ende DateTime @db.Date
meldebeginn DateTime
meldeschluss DateTime
ortId Int?
ort Ort? @relation(fields: [ortId], references: [id], onDelete: SetNull)
maxTeilnehmende Int
teilnahmegebuehr Int
unterveranstaltungen Unterveranstaltung[]
mahlzeiten Mahlzeit[]
beschreibung String?
datenschutz String?
teilnahmeBedingungen String?
teilnahmeBedingungenPublic String?
zielgruppe String?
hostnameId Int?
hostname Hostname? @relation(fields: [hostnameId], references: [id])
customFields CustomField[]
}

enum MahlzeitType {
Expand Down Expand Up @@ -306,15 +310,15 @@ enum ActivityType {
}

model Activity {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
type ActivityType
description String?
subjectType String
subjectId Int?
causerId Int?
causer Account? @relation(fields: [causerId], references: [id], onDelete: SetNull)
metadata Json @default("{}")
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
type ActivityType
description String?
subjectType String
subjectId Int?
causerId Int?
causer Account? @relation(fields: [causerId], references: [id], onDelete: SetNull)
metadata Json @default("{}")
}

enum CustomFieldType {
Expand All @@ -335,26 +339,26 @@ enum CustomFieldPosition {
}

model CustomField {
id Int @id @default(autoincrement())
name String
description String?
type CustomFieldType
required Boolean @default(false)
options String[]
role Role[]
values CustomFieldValue[]
positions CustomFieldPosition[]
veranstaltungId Int?
unterveranstaltungId Int?
veranstaltung Veranstaltung? @relation(fields: [veranstaltungId], references: [id], onDelete: Cascade)
unterveranstaltung Unterveranstaltung? @relation(fields: [unterveranstaltungId], references: [id], onDelete: Cascade)
id Int @id @default(autoincrement())
name String
description String?
type CustomFieldType
required Boolean @default(false)
options String[]
role Role[]
values CustomFieldValue[]
positions CustomFieldPosition[]
veranstaltungId Int?
unterveranstaltungId Int?
veranstaltung Veranstaltung? @relation(fields: [veranstaltungId], references: [id], onDelete: Cascade)
unterveranstaltung Unterveranstaltung? @relation(fields: [unterveranstaltungId], references: [id], onDelete: Cascade)
}

model CustomFieldValue {
id Int @id @default(autoincrement())
value Json @default("{}")
fieldId Int
field CustomField @relation(fields: [fieldId], references: [id], onDelete: Cascade)
anmeldungId Int?
anmeldung Anmeldung? @relation(fields: [anmeldungId], references: [id], onDelete: Cascade)
id Int @id @default(autoincrement())
value Json @default("{}")
fieldId Int
field CustomField @relation(fields: [fieldId], references: [id], onDelete: Cascade)
anmeldungId Int?
anmeldung Anmeldung? @relation(fields: [anmeldungId], references: [id], onDelete: Cascade)
}
3 changes: 2 additions & 1 deletion api/prisma/seeders/anmeldungen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ async function create(prisma: PrismaClient, unterveranstaltung: Unterveranstaltu
city: faker.location.city(),
zip: faker.location.zipCode(),
street: faker.location.street(),
number: faker.location.buildingNumber(),
streetNumber: faker.location.buildingNumber(),
country: 'DE',
},
select: {
id: true,
Expand Down
3 changes: 2 additions & 1 deletion api/prisma/seeders/veranstaltung.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const createVeranstaltung: Seeder = async (prisma: PrismaClient) => {
create: {
city: 'Langwedel',
zip: '24631',
number: '1',
streetNumber: '1',
street: 'Am Waldheim',
country: 'DE',
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export const configSchema = z.strictObject({
host: z.string(),
apiKey: z.string(),
}),
tomtom: z.strictObject({
apiKey: z.string(),
}),
})

export default configSchema.parse(baseConfig)
10 changes: 10 additions & 0 deletions api/src/services/address/address.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable prettier/prettier */ // Prettier ignored is because this file is generated
import { mergeRouters } from '../../trpc'

import { addressFindActionProcedure } from './addressFindAddress'
// Import Routes here - do not delete this line

export const addressRouter = mergeRouters(
addressFindActionProcedure.router,
// Add Routes here - do not delete this line
)
69 changes: 69 additions & 0 deletions api/src/services/address/addressFindAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import axios from 'axios'
import z from 'zod'

import config from '../../config'
import { defineProcedure } from '../../types/defineProcedure'

export const addressFindActionProcedure = defineProcedure({
key: 'findAddress',
method: 'query',
protection: { type: 'public' },
inputSchema: z.object({
query: z.string().optional(),
zip: z.string().optional(),
city: z.string().optional(),
street: z.string().optional(),
streetNumber: z.string().optional(),
country: z.string().optional(),
}),

async handler(options) {
let searchText = ''
if (options.input.query != null) {
searchText = options.input.query
} else {
if (options.input.zip != null) {
searchText += options.input.zip
}
if (options.input.city != null) {
searchText += options.input.city
}
if (options.input.street != null) {
searchText += options.input.street
}
if (options.input.streetNumber != null) {
searchText += options.input.streetNumber
}
}
const language = 'NGT'

let results

const token = config.tomtom.apiKey
const country = options?.input?.country != null ? options.input.country.toUpperCase() : 'DE'

try {
const query = await axios.get(
`https://api.tomtom.com/search/2/search/${encodeURIComponent(
searchText
)}.json?typeahead=true&limit=5&countrySet=${country}&language=${language}&idxSet=PAD&minFuzzyLevel=1&maxFuzzyLevel=2&view=Unified&key=${token}`
)
if (query.data.summary.numResults < 1) return []
results = query.data.results.map((result) => {
return {
street: result.address.streetName,
streetNumber: result.address.streetNumber,
zip: result.address.postalCode,
city: result.address.municipality,
country: result.address.countryCode,
position: result.position,
}
})
} catch (e) {
// eslint-disable-next-line no-console
console.error(e)
return []
}
return results
},
})
Loading

0 comments on commit 28355e6

Please sign in to comment.