Add country_code field to userVisitedWorldTravel table
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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 }), {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
},
|
||||
body: JSON.stringify({
|
||||
region_id: event.detail,
|
||||
country_code: data.countrycode,
|
||||
}),
|
||||
}).then((response) => {
|
||||
if (response.status === 401) {
|
||||
|
||||
Reference in New Issue
Block a user