From 98a3771516e738c5a08bbeff64697b892addd1eb Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Wed, 26 Apr 2023 20:51:14 +0300 Subject: [PATCH] replacing the example of migration file --- src/handlers.ts | 16 ++++++++-------- .../20230424234230_create_timeslots_table.js | 14 +++++++------- src/types/index.js | 2 -- src/types/index.ts | 7 +++++++ 4 files changed, 22 insertions(+), 17 deletions(-) delete mode 100644 src/types/index.js diff --git a/src/handlers.ts b/src/handlers.ts index 64a6765..24a44f8 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -2,7 +2,7 @@ import { Request, Response } from 'express'; import dateModule from 'date-and-time'; import { resolveAddress } from './geocoding'; -import { Address, AvailableTimeslots } from './types'; +import { Address, AvailableTimeslots, Orders } from './types'; import { randomUUID } from 'crypto'; import { getAvailableTimeSlots } from './services/timeslotsService'; import { getHolidays } from './services/holidaysService'; @@ -28,7 +28,7 @@ export const resolveAddressHandler = (req: Request, res: Response) => { }) }; -export const timeslotsHandler = async (req: Request, res: Response) => { +export const timeslotsHandler = async (req: Request, res: Response): Promise => { if (!req.body.address) { res.status(400).json({ error: 'Missing address' }); return; @@ -46,7 +46,7 @@ export const timeslotsHandler = async (req: Request, res: Response) => { return; }; -export const deliveriesHandler = (req: Request, res: Response) => { +export const deliveriesHandler = (req: Request, res: Response): void => { const userId = req.body.userId; const slotId = req.body.timeslotId; @@ -107,7 +107,7 @@ export const deliveriesHandler = (req: Request, res: Response) => { }; -export const cancelDeliveryHandler = (req: Request, res: Response) => { +export const cancelDeliveryHandler = (req: Request, res: Response): void => { // TODO: Implement cancel delivery functionality // DELETE /deliveries/:deliveryId const deliveryId = req.params.deliveryId; @@ -136,11 +136,11 @@ export const cancelDeliveryHandler = (req: Request, res: Response) => { return; }; -export const dailyDeliveriesHandler = (req: Request, res: Response) => { +export const dailyDeliveriesHandler = (req: Request, res: Response): void => { // TODO: Implement daily deliveries functionality // GET /deliveries/daily - retrieve all today’s deliveries - by today in ordersByDates const date = dateModule.format(new Date(), dateFormat).split(' ')[0]; - const todaysOrders = []; + const todaysOrders: Orders[] = []; if (ordersByDates.has(date)) { ordersByDates.get(date).forEach((orderId) => { todaysOrders.push(deliveriesCache.get(orderId)); @@ -151,13 +151,13 @@ export const dailyDeliveriesHandler = (req: Request, res: Response) => { return; }; -export const weeklyDeliveriesHandler = (req: Request, res: Response) => { +export const weeklyDeliveriesHandler = (req: Request, res: Response): void => { // TODO: Implement weekly deliveries functionality // GET /deliveries/weekly - retrieve all week deliveries - from today to 7 days later in ordersByDates // this array will contain 7 elements - each element will be dates in the next 7 days // ["today", "tomorrow" ... ] const today = new Date(); - const weeklyOrders = []; + const weeklyOrders: Orders [] = []; for (let i = 0; i < 7; i++) { const date = dateModule.format(new Date(today.setDate(today.getDate() + i)), dateFormat).split(' ')[0]; if (ordersByDates.has(date)) { diff --git a/src/migrations/20230424234230_create_timeslots_table.js b/src/migrations/20230424234230_create_timeslots_table.js index 2c38688..3665335 100644 --- a/src/migrations/20230424234230_create_timeslots_table.js +++ b/src/migrations/20230424234230_create_timeslots_table.js @@ -1,13 +1,13 @@ exports.up = function(knex) { - return knex.schema.createTable('timeslots', function(table) { - table.increments('id').primary(); - table.timestamp('start_time').notNullable(); - table.timestamp('end_time').notNullable(); - table.boolean('is_reserved').notNullable().defaultTo(false); - table.timestamps(true, true); + return knex.schema.createTable('orders', function(table) { + table.string('_id', 36).primary(); + table.string('userId', 36).notNullable(); + table.string('slotId', 36).notNullable(); + table.string('deliveryCreatedDate', 255).notNullable(); }); }; + exports.down = function(knex) { - return knex.schema.dropTable('timeslots'); + return knex.schema.dropTable('orders'); }; \ No newline at end of file diff --git a/src/types/index.js b/src/types/index.js deleted file mode 100644 index c8ad2e5..0000000 --- a/src/types/index.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/src/types/index.ts b/src/types/index.ts index 0c12fa8..1a3f16c 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -11,4 +11,11 @@ export interface AvailableTimeslots { id: string; start_time: string; end_time: string; +} + +export interface Orders { + _id: string; + userId: string; + slotId: string; + deliveryCreatedDate: string; } \ No newline at end of file