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 dateModule from 'date-and-time';
|
||||||
|
|
||||||
import { resolveAddress } from './geocoding';
|
import { resolveAddress } from './geocoding';
|
||||||
import { Address, AvailableTimeslots } from './types';
|
import { Address, AvailableTimeslots, Orders } from './types';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { getAvailableTimeSlots } from './services/timeslotsService';
|
import { getAvailableTimeSlots } from './services/timeslotsService';
|
||||||
import { getHolidays } from './services/holidaysService';
|
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) {
|
if (!req.body.address) {
|
||||||
res.status(400).json({ error: 'Missing address' });
|
res.status(400).json({ error: 'Missing address' });
|
||||||
return;
|
return;
|
||||||
|
@ -46,7 +46,7 @@ export const timeslotsHandler = async (req: Request, res: Response) => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deliveriesHandler = (req: Request, res: Response) => {
|
export const deliveriesHandler = (req: Request, res: Response): void => {
|
||||||
const userId = req.body.userId;
|
const userId = req.body.userId;
|
||||||
const slotId = req.body.timeslotId;
|
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
|
// TODO: Implement cancel delivery functionality
|
||||||
// DELETE /deliveries/:deliveryId
|
// DELETE /deliveries/:deliveryId
|
||||||
const deliveryId = req.params.deliveryId;
|
const deliveryId = req.params.deliveryId;
|
||||||
|
@ -136,11 +136,11 @@ export const cancelDeliveryHandler = (req: Request, res: Response) => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const dailyDeliveriesHandler = (req: Request, res: Response) => {
|
export const dailyDeliveriesHandler = (req: Request, res: Response): void => {
|
||||||
// TODO: Implement daily deliveries functionality
|
// TODO: Implement daily deliveries functionality
|
||||||
// GET /deliveries/daily - retrieve all today’s deliveries - by today in ordersByDates
|
// GET /deliveries/daily - retrieve all today’s deliveries - by today in ordersByDates
|
||||||
const date = dateModule.format(new Date(), dateFormat).split(' ')[0];
|
const date = dateModule.format(new Date(), dateFormat).split(' ')[0];
|
||||||
const todaysOrders = [];
|
const todaysOrders: Orders[] = [];
|
||||||
if (ordersByDates.has(date)) {
|
if (ordersByDates.has(date)) {
|
||||||
ordersByDates.get(date).forEach((orderId) => {
|
ordersByDates.get(date).forEach((orderId) => {
|
||||||
todaysOrders.push(deliveriesCache.get(orderId));
|
todaysOrders.push(deliveriesCache.get(orderId));
|
||||||
|
@ -151,13 +151,13 @@ export const dailyDeliveriesHandler = (req: Request, res: Response) => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const weeklyDeliveriesHandler = (req: Request, res: Response) => {
|
export const weeklyDeliveriesHandler = (req: Request, res: Response): void => {
|
||||||
// TODO: Implement weekly deliveries functionality
|
// TODO: Implement weekly deliveries functionality
|
||||||
// GET /deliveries/weekly - retrieve all week deliveries - from today to 7 days later in ordersByDates
|
// 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
|
// this array will contain 7 elements - each element will be dates in the next 7 days
|
||||||
// ["today", "tomorrow" ... ]
|
// ["today", "tomorrow" ... ]
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const weeklyOrders = [];
|
const weeklyOrders: Orders [] = [];
|
||||||
for (let i = 0; i < 7; i++) {
|
for (let i = 0; i < 7; i++) {
|
||||||
const date = dateModule.format(new Date(today.setDate(today.getDate() + i)), dateFormat).split(' ')[0];
|
const date = dateModule.format(new Date(today.setDate(today.getDate() + i)), dateFormat).split(' ')[0];
|
||||||
if (ordersByDates.has(date)) {
|
if (ordersByDates.has(date)) {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
exports.up = function(knex) {
|
exports.up = function(knex) {
|
||||||
return knex.schema.createTable('timeslots', function(table) {
|
return knex.schema.createTable('orders', function(table) {
|
||||||
table.increments('id').primary();
|
table.string('_id', 36).primary();
|
||||||
table.timestamp('start_time').notNullable();
|
table.string('userId', 36).notNullable();
|
||||||
table.timestamp('end_time').notNullable();
|
table.string('slotId', 36).notNullable();
|
||||||
table.boolean('is_reserved').notNullable().defaultTo(false);
|
table.string('deliveryCreatedDate', 255).notNullable();
|
||||||
table.timestamps(true, true);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.down = function(knex) {
|
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 });
|
|
|
@ -12,3 +12,10 @@ export interface AvailableTimeslots {
|
||||||
start_time: string;
|
start_time: string;
|
||||||
end_time: string;
|
end_time: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Orders {
|
||||||
|
_id: string;
|
||||||
|
userId: string;
|
||||||
|
slotId: string;
|
||||||
|
deliveryCreatedDate: string;
|
||||||
|
}
|
Loading…
Reference in a new issue