replacing the example of migration file
This commit is contained in:
parent
b92a569e04
commit
98a3771516
4 changed files with 22 additions and 17 deletions
|
@ -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<void> => {
|
||||
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)) {
|
||||
|
|
|
@ -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');
|
||||
};
|
|
@ -1,2 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue