-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(interfaces): Add enums.ts to @codeanker/interfaces package
Add the enums.ts file to the @codeanker/interfaces package, which exports the Countries enum.
- Loading branch information
1 parent
6edb81f
commit 28355e6
Showing
26 changed files
with
2,903 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
api/prisma/migrations/20240907155549_rename_address_schema/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
9 changes: 9 additions & 0 deletions
9
api/prisma/migrations/20240907172928_add_field_to_address/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
12 changes: 12 additions & 0 deletions
12
api/prisma/migrations/20240907174812_edit_fields_address/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}) |
Oops, something went wrong.