Skip to content

Commit

Permalink
Edit schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadjaur committed Dec 15, 2024
1 parent 5e9251c commit c349373
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const addTripDetails = z.object({
bounds: z.tuple([z.array(z.number()), z.array(z.number())]).optional(),
end_date: z.string(),
geoJSON: z.string(),
packId: z.string(),
pack_id: z.string(),
parks: z.string().optional(),
start_date: z.string(),
trails: z.string().optional(),
Expand All @@ -60,19 +60,11 @@ export const addTripDetails = z.object({
export const addTrip = addTripDetails.merge(addTripForm);
export type AddTripType = z.infer<typeof addTrip>;

export const editTrip = z.object({
activity: z.enum(tripActivityValues).optional(),
bounds: z.array(z.array(z.number())).length(2).optional(),
description: z.string().optional(),
end_date: z.string().optional(),
geoJSON: z.string().optional(),
name: z.string().optional(),
packId: z.string().optional(),
parks: z.string().optional(),
start_date: z.string().optional(),
trails: z.string().optional(),
id: z.string().min(1),
});
export const editTrip = addTrip.merge(
z.object({
id: z.string().min(1),
}),
);

export type EditTripType = z.infer<typeof editTrip>;

Expand Down
2 changes: 1 addition & 1 deletion server/src/drizzle/methods/trip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../../db/schema';

export class Trip {
async update(trip: Partial<InsertTrip>) {
async update(trip: InsertTrip) {
try {
if (!trip.id) {
throw new Error('Trip id is required for update operation');
Expand Down
6 changes: 2 additions & 4 deletions server/src/services/trip/addTripService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import * as validator from '@packrat/validations';
import { calculateTripScore } from 'src/utils/scoreTrip';
import { GeoJson } from '../../drizzle/methods/Geojson';
import { TripGeoJson } from '../../drizzle/methods/TripGeoJson';
import { Trip } from '../../drizzle/methods/trip';
import { validateGeojsonId, validateGeojsonType } from '../../utils/geojson';
import { GeojsonStorageService } from '../geojsonStorage';
import { scoreTripService } from './scoreTripService';
import { trip } from 'src/db/schema';

export const addTripService = async (
tripData: validator.AddTripType & { ownerId: string },
Expand All @@ -22,8 +19,9 @@ export const addTripService = async (
description: tripData.description,
start_date: tripData.start_date,
end_date: tripData.end_date,
activity: tripData.activity,
activity: tripData.activity || 'trip',
owner_id: tripData.ownerId,
pack_id: tripData.pack_id,
is_public: tripData.is_public === '0',
trails: tripData.trails ? JSON.parse(tripData.trails) : null,
parks: tripData.parks ? JSON.parse(tripData.parks) : null,
Expand Down
1 change: 1 addition & 0 deletions server/src/services/trip/editTripService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const editTripService = async (
start_date: tripData.start_date || selectedTrip.start_date,
end_date: tripData.end_date || selectedTrip.end_date,
activity: tripData.activity || selectedTrip.activity,
pack_id: tripData.pack_id || selectedTrip.pack_id,
trails: tripData.trails
? JSON.parse(tripData.trails)
: selectedTrip.trails,
Expand Down

0 comments on commit c349373

Please sign in to comment.