Add country_code field to userVisitedWorldTravel table

This commit is contained in:
Sean Morley
2024-04-14 13:39:32 +00:00
parent 5e1d7ef160
commit c5ce984cac
7 changed files with 411 additions and 2 deletions

View File

@@ -70,6 +70,9 @@ export const worldTravelCountryRegions = pgTable("worldTravelCountryRegions", {
export const userVisitedWorldTravel = pgTable("userVisitedWorldTravel", {
id: serial("id").primaryKey(),
country_code: text("country_code")
.notNull()
.references(() => worldTravelCountries.country_code),
userId: text("user_id")
.notNull()
.references(() => userTable.id),

View File

@@ -18,6 +18,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
.values({
userId: event.locals.user.id,
region_id: body.region_id,
country_code: body.country_code,
})
.execute();
return new Response(JSON.stringify({ res: res }), {

View File

@@ -1,6 +1,6 @@
import { db } from '$lib/db/db.server.js';
import { userVisitedWorldTravel, worldTravelCountryRegions } from '$lib/db/schema.js';
import { eq } from 'drizzle-orm';
import { and, eq } from 'drizzle-orm';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ params, locals }) => {
@@ -13,10 +13,16 @@ export const load: PageServerLoad = async ({ params, locals }) => {
let visitedRegions: { id: number; userId: string; region_id: string; }[] = [];
if (locals.user) {
let countryCode = params.countrycode
visitedRegions = await db
.select()
.from(userVisitedWorldTravel)
.where(eq(userVisitedWorldTravel.userId, locals.user.id))
.where(
and(
eq(userVisitedWorldTravel.userId, locals.user.id),
eq(userVisitedWorldTravel.country_code, countryCode)
)
)
.execute();
}

View File

@@ -15,6 +15,7 @@
},
body: JSON.stringify({
region_id: event.detail,
country_code: data.countrycode,
}),
}).then((response) => {
if (response.status === 401) {