server-core-module 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controllers/delivery.controller.d.ts +8 -0
- package/dist/controllers/delivery.controller.js +82 -0
- package/dist/models/delivery.model.d.ts +13 -0
- package/dist/models/delivery.model.js +25 -0
- package/dist/repositories/delivery.repository.d.ts +25 -0
- package/dist/repositories/delivery.repository.js +107 -0
- package/package.json +1 -1
- package/src/controllers/delivery.controller.ts +97 -0
- package/src/models/delivery.model.ts +32 -0
- package/src/repositories/delivery.repository.ts +120 -0
- package/src/utils/email.service.ts +17 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
export declare function useDeliveryController(): {
|
|
3
|
+
add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
4
|
+
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
5
|
+
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
6
|
+
updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
7
|
+
deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDeliveryController = useDeliveryController;
|
|
4
|
+
const delivery_model_1 = require("../models/delivery.model");
|
|
5
|
+
const delivery_repository_1 = require("../repositories/delivery.repository");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
function useDeliveryController() {
|
|
8
|
+
const { getAll: _getAll, add: _add, getById: _getById, deleteById: _deleteById, updateById: _updateById } = (0, delivery_repository_1.useDeliveryRepository)();
|
|
9
|
+
async function add(req, res, next) {
|
|
10
|
+
const value = req.body;
|
|
11
|
+
const { error } = delivery_model_1.schemaDelivery.validate(value);
|
|
12
|
+
if (error) {
|
|
13
|
+
next(new error_1.BadRequestError(error.details[0].message));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const message = await _add(value);
|
|
18
|
+
res.json({ message });
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
next(error);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function getAll(req, res, next) {
|
|
25
|
+
try {
|
|
26
|
+
const page = Number(req.query.page) || 1;
|
|
27
|
+
const limit = Number(req.query.limit) || 10;
|
|
28
|
+
const items = await _getAll({ page, limit });
|
|
29
|
+
res.json(items);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
next(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function getById(req, res, next) {
|
|
36
|
+
const id = req.params.id;
|
|
37
|
+
try {
|
|
38
|
+
const item = await _getById(id);
|
|
39
|
+
res.json(item);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
next(error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function updateById(req, res, next) {
|
|
46
|
+
try {
|
|
47
|
+
const id = req.params.id;
|
|
48
|
+
const value = req.body;
|
|
49
|
+
const { error } = delivery_model_1.schemaDeliveryUpdate.validate(value);
|
|
50
|
+
if (error) {
|
|
51
|
+
next(new error_1.BadRequestError(error.message));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const updated = await _updateById(id, value);
|
|
55
|
+
if (!updated) {
|
|
56
|
+
res.status(404).json({ message: "Delivery not found" });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
res.json({ message: "Delivery updated successfully", updated });
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
next(error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function deleteById(req, res, next) {
|
|
66
|
+
try {
|
|
67
|
+
const id = req.params.id;
|
|
68
|
+
await _deleteById(id);
|
|
69
|
+
res.json({ message: "Delivery deleted successfully" });
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
next(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
add,
|
|
77
|
+
getAll,
|
|
78
|
+
getById,
|
|
79
|
+
updateById,
|
|
80
|
+
deleteById,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
import { ObjectId } from 'mongodb';
|
|
3
|
+
export type Tdelivery = {
|
|
4
|
+
_id?: ObjectId;
|
|
5
|
+
locationName: string;
|
|
6
|
+
motorcycleFee: number;
|
|
7
|
+
sedanFee: number;
|
|
8
|
+
createdAt?: Date;
|
|
9
|
+
updatedAt?: Date;
|
|
10
|
+
};
|
|
11
|
+
export declare const schemaDelivery: Joi.ObjectSchema<any>;
|
|
12
|
+
export declare const schemaDeliveryUpdate: Joi.ObjectSchema<any>;
|
|
13
|
+
export declare function modelDelivery(value: Tdelivery): Tdelivery;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.schemaDeliveryUpdate = exports.schemaDelivery = void 0;
|
|
7
|
+
exports.modelDelivery = modelDelivery;
|
|
8
|
+
const joi_1 = __importDefault(require("joi"));
|
|
9
|
+
exports.schemaDelivery = joi_1.default.object({
|
|
10
|
+
locationName: joi_1.default.string().required(),
|
|
11
|
+
motorcycleFee: joi_1.default.number().required(),
|
|
12
|
+
sedanFee: joi_1.default.number().required(),
|
|
13
|
+
});
|
|
14
|
+
exports.schemaDeliveryUpdate = joi_1.default.object({
|
|
15
|
+
locationName: joi_1.default.string().optional(),
|
|
16
|
+
motorcycleFee: joi_1.default.number().optional(),
|
|
17
|
+
sedanFee: joi_1.default.number().optional(),
|
|
18
|
+
});
|
|
19
|
+
function modelDelivery(value) {
|
|
20
|
+
return {
|
|
21
|
+
...value,
|
|
22
|
+
createdAt: value.createdAt || new Date(),
|
|
23
|
+
updatedAt: new Date(),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ObjectId, Db } from "mongodb";
|
|
2
|
+
import { Tdelivery } from "../models/delivery.model";
|
|
3
|
+
export declare function setDb(database: Db): void;
|
|
4
|
+
export declare function useDeliveryRepository(): {
|
|
5
|
+
add: (value: Tdelivery) => Promise<ObjectId>;
|
|
6
|
+
getAll: ({ page, limit, }?: {
|
|
7
|
+
page?: number;
|
|
8
|
+
limit?: number;
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
items: any[];
|
|
11
|
+
totalPages: number;
|
|
12
|
+
currentPage: number;
|
|
13
|
+
pages?: undefined;
|
|
14
|
+
pageRange?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
items: any[];
|
|
17
|
+
pages: number;
|
|
18
|
+
pageRange: string;
|
|
19
|
+
totalPages?: undefined;
|
|
20
|
+
currentPage?: undefined;
|
|
21
|
+
}>;
|
|
22
|
+
getById: (id: string) => Promise<import("mongodb").WithId<import("bson").Document>>;
|
|
23
|
+
updateById: (id: string, value: Partial<Tdelivery>) => Promise<number>;
|
|
24
|
+
deleteById: (id: string) => Promise<string>;
|
|
25
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setDb = setDb;
|
|
4
|
+
exports.useDeliveryRepository = useDeliveryRepository;
|
|
5
|
+
const mongodb_1 = require("mongodb");
|
|
6
|
+
const delivery_model_1 = require("../models/delivery.model");
|
|
7
|
+
const paginate_util_1 = require("../utils/paginate.util");
|
|
8
|
+
let db;
|
|
9
|
+
function setDb(database) {
|
|
10
|
+
db = database;
|
|
11
|
+
}
|
|
12
|
+
;
|
|
13
|
+
function useDeliveryRepository() {
|
|
14
|
+
const collection = db.collection('delivery');
|
|
15
|
+
//CREATE INDEXES
|
|
16
|
+
async function createIndexes() {
|
|
17
|
+
try {
|
|
18
|
+
await collection.createIndexes([
|
|
19
|
+
{ key: { locationName: 1 } },
|
|
20
|
+
{ key: { createdAt: 1 } },
|
|
21
|
+
]);
|
|
22
|
+
return "Indexes created successfully";
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new Error(`Error creating indexes: ${error.message}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//ADD PRODUCT
|
|
29
|
+
async function add(value) {
|
|
30
|
+
try {
|
|
31
|
+
value = (0, delivery_model_1.modelDelivery)(value);
|
|
32
|
+
const result = await collection.insertOne(value);
|
|
33
|
+
return result.insertedId;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw new Error(`Error adding delivery: ${error.message}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//GET ALL PRODUCTS
|
|
40
|
+
async function getAll({ page = 1, limit = 10, } = {}) {
|
|
41
|
+
page = page > 0 ? page - 1 : 0;
|
|
42
|
+
const query = {};
|
|
43
|
+
try {
|
|
44
|
+
const items = await collection.aggregate([
|
|
45
|
+
{ $match: query },
|
|
46
|
+
{ $skip: page * limit },
|
|
47
|
+
{ $limit: limit },
|
|
48
|
+
]).toArray();
|
|
49
|
+
const length = await collection.countDocuments(query);
|
|
50
|
+
return (0, paginate_util_1.paginate)(items, page, limit, length);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new Error("Failed to get delivery: " + error.message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//GET PRODUCT BY ID
|
|
57
|
+
async function getById(id) {
|
|
58
|
+
try {
|
|
59
|
+
const item = await collection.findOne({ _id: new mongodb_1.ObjectId(id) });
|
|
60
|
+
return item;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw new Error("Failed to get Delivery: " + error);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//UPDATE BY ID
|
|
67
|
+
async function updateById(id, value) {
|
|
68
|
+
try {
|
|
69
|
+
new mongodb_1.ObjectId(id);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw new Error("Invalid ID format ");
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
value.updatedAt = new Date();
|
|
76
|
+
const result = await collection.updateOne({ _id: new mongodb_1.ObjectId(id) }, { $set: value });
|
|
77
|
+
return result.modifiedCount;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
throw new Error("Failed to update Delivery: " + error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//DELETE BY ID
|
|
84
|
+
async function deleteById(id) {
|
|
85
|
+
try {
|
|
86
|
+
id = new mongodb_1.ObjectId(id);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw new Error("Failed to delete Delivery: " + error);
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
await collection.deleteOne({ _id: id });
|
|
93
|
+
return "Delivery Deleted Successfully";
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
throw new Error("Failed to delete Delivery: " + error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
add,
|
|
101
|
+
getAll,
|
|
102
|
+
getById,
|
|
103
|
+
updateById,
|
|
104
|
+
deleteById,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
;
|
package/package.json
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { schemaDelivery, schemaDeliveryUpdate } from '../models/delivery.model';
|
|
3
|
+
import { useDeliveryRepository } from '../repositories/delivery.repository';
|
|
4
|
+
import { BadRequestError } from '../error';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export function useDeliveryController() {
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
getAll: _getAll,
|
|
11
|
+
add: _add,
|
|
12
|
+
getById: _getById,
|
|
13
|
+
deleteById: _deleteById,
|
|
14
|
+
updateById: _updateById
|
|
15
|
+
} = useDeliveryRepository();
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async function add(req: Request, res: Response, next: NextFunction) {
|
|
19
|
+
const value = req.body;
|
|
20
|
+
const { error } = schemaDelivery.validate(value);
|
|
21
|
+
|
|
22
|
+
if(error) {
|
|
23
|
+
next(new BadRequestError(error.details[0].message));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const message = await _add(value);
|
|
28
|
+
res.json({message});
|
|
29
|
+
} catch (error) {
|
|
30
|
+
next(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function getAll(req: Request, res: Response, next: NextFunction) {
|
|
35
|
+
try {
|
|
36
|
+
const page = Number(req.query.page) || 1;
|
|
37
|
+
const limit = Number(req.query.limit) || 10;
|
|
38
|
+
const items = await _getAll({page, limit})
|
|
39
|
+
res.json(items);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
next(error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function getById(req: Request, res: Response, next: NextFunction) {
|
|
46
|
+
const id = req.params.id as string;
|
|
47
|
+
try {
|
|
48
|
+
const item = await _getById(id);
|
|
49
|
+
res.json(item);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
next(error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function updateById(req: Request, res: Response, next: NextFunction) {
|
|
56
|
+
try {
|
|
57
|
+
const id = req.params.id as string;
|
|
58
|
+
const value = req.body;
|
|
59
|
+
const { error } = schemaDeliveryUpdate.validate(value);
|
|
60
|
+
|
|
61
|
+
if(error) {
|
|
62
|
+
next(new BadRequestError(error.message));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const updated = await _updateById(id, value);
|
|
67
|
+
if(!updated){
|
|
68
|
+
res.status(404).json({message: "Delivery not found"});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
res.json({message: "Delivery updated successfully", updated});
|
|
73
|
+
} catch (error) {
|
|
74
|
+
next(error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function deleteById(req: Request, res: Response, next: NextFunction) {
|
|
79
|
+
try {
|
|
80
|
+
const id = req.params.id as string;
|
|
81
|
+
await _deleteById(id);
|
|
82
|
+
res.json({message: "Delivery deleted successfully"});
|
|
83
|
+
} catch (error) {
|
|
84
|
+
next(error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return{
|
|
89
|
+
add,
|
|
90
|
+
getAll,
|
|
91
|
+
getById,
|
|
92
|
+
updateById,
|
|
93
|
+
deleteById,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
import { ObjectId } from 'mongodb';
|
|
3
|
+
|
|
4
|
+
export type Tdelivery = {
|
|
5
|
+
_id?: ObjectId;
|
|
6
|
+
locationName: string;
|
|
7
|
+
motorcycleFee: number;
|
|
8
|
+
sedanFee: number;
|
|
9
|
+
createdAt?: Date;
|
|
10
|
+
updatedAt?: Date;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const schemaDelivery = Joi.object({
|
|
14
|
+
locationName: Joi.string().required(),
|
|
15
|
+
motorcycleFee:Joi.number().required(),
|
|
16
|
+
sedanFee:Joi.number().required(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const schemaDeliveryUpdate = Joi.object({
|
|
20
|
+
locationName: Joi.string().optional(),
|
|
21
|
+
motorcycleFee:Joi.number().optional(),
|
|
22
|
+
sedanFee:Joi.number().optional(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export function modelDelivery (value:Tdelivery): Tdelivery{
|
|
26
|
+
return{
|
|
27
|
+
...value,
|
|
28
|
+
createdAt: value.createdAt || new Date(),
|
|
29
|
+
updatedAt: new Date(),
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Collection, ObjectId, Db } from "mongodb";
|
|
2
|
+
import { Tdelivery, modelDelivery } from "../models/delivery.model";
|
|
3
|
+
import { paginate } from "../utils/paginate.util";
|
|
4
|
+
|
|
5
|
+
let db: Db;
|
|
6
|
+
|
|
7
|
+
export function setDb(database:Db){
|
|
8
|
+
db = database;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function useDeliveryRepository(){
|
|
12
|
+
const collection = db.collection('delivery');
|
|
13
|
+
|
|
14
|
+
//CREATE INDEXES
|
|
15
|
+
|
|
16
|
+
async function createIndexes(){
|
|
17
|
+
try {
|
|
18
|
+
await collection.createIndexes([
|
|
19
|
+
{ key: { locationName:1}},
|
|
20
|
+
{ key: { createdAt:1}},
|
|
21
|
+
]);
|
|
22
|
+
return "Indexes created successfully"
|
|
23
|
+
} catch (error:any) {
|
|
24
|
+
throw new Error(`Error creating indexes: ${error.message}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//ADD PRODUCT
|
|
29
|
+
|
|
30
|
+
async function add(value:Tdelivery) {
|
|
31
|
+
try {
|
|
32
|
+
value = modelDelivery(value)
|
|
33
|
+
const result = await collection.insertOne(value);
|
|
34
|
+
return result.insertedId;
|
|
35
|
+
} catch (error:any) {
|
|
36
|
+
throw new Error(`Error adding delivery: ${error.message}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//GET ALL PRODUCTS
|
|
41
|
+
|
|
42
|
+
async function getAll({
|
|
43
|
+
page = 1,
|
|
44
|
+
limit = 10,
|
|
45
|
+
} = {}) {
|
|
46
|
+
page = page > 0 ? page - 1 : 0;
|
|
47
|
+
const query: any = {};
|
|
48
|
+
try {
|
|
49
|
+
const items = await collection.aggregate([
|
|
50
|
+
{$match:query},
|
|
51
|
+
{$skip: page * limit},
|
|
52
|
+
{$limit : limit},
|
|
53
|
+
]).toArray();
|
|
54
|
+
|
|
55
|
+
const length = await collection.countDocuments(query);
|
|
56
|
+
return paginate(items, page, limit, length);
|
|
57
|
+
} catch (error:any) {
|
|
58
|
+
throw new Error("Failed to get delivery: " + error.message);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//GET PRODUCT BY ID
|
|
63
|
+
|
|
64
|
+
async function getById(id: string) {
|
|
65
|
+
try {
|
|
66
|
+
const item =await collection.findOne({_id: new ObjectId(id)});
|
|
67
|
+
return item;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
throw new Error("Failed to get Delivery: " + error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//UPDATE BY ID
|
|
74
|
+
|
|
75
|
+
async function updateById(id:string, value: Partial<Tdelivery>){
|
|
76
|
+
try {
|
|
77
|
+
new ObjectId(id);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new Error("Invalid ID format ")
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
value.updatedAt = new Date();
|
|
84
|
+
const result = await collection.updateOne(
|
|
85
|
+
{_id: new ObjectId(id)},
|
|
86
|
+
{$set:value},
|
|
87
|
+
)
|
|
88
|
+
return result.modifiedCount
|
|
89
|
+
} catch (error) {
|
|
90
|
+
throw new Error("Failed to update Delivery: " + error)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
//DELETE BY ID
|
|
96
|
+
async function deleteById(id:string) {
|
|
97
|
+
try {
|
|
98
|
+
id = new ObjectId(id) as any
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw new Error("Failed to delete Delivery: " + error)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await collection.deleteOne({_id: id as any})
|
|
105
|
+
return "Delivery Deleted Successfully"
|
|
106
|
+
} catch (error) {
|
|
107
|
+
throw new Error("Failed to delete Delivery: " + error)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return{
|
|
112
|
+
add,
|
|
113
|
+
getAll,
|
|
114
|
+
getById,
|
|
115
|
+
updateById,
|
|
116
|
+
deleteById,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
};
|
|
@@ -51,14 +51,28 @@ export async function sendOrderConfirmation(email: string, name: string, items:
|
|
|
51
51
|
|
|
52
52
|
export async function sendOrderStatusUpdate(email: string, name: string, status: string) {
|
|
53
53
|
try {
|
|
54
|
+
|
|
55
|
+
let subject = `Order ${status}! 🌸`
|
|
56
|
+
let message = `Your order is now <strong>${status}</strong>! 🌸`
|
|
57
|
+
|
|
58
|
+
if(status === 'confirmed') {
|
|
59
|
+
subject = 'Order Confirmed! 🌸'
|
|
60
|
+
message = 'We are now preparing your beautiful flowers! 🌸'
|
|
61
|
+
} else if(status === 'out_for_delivery') {
|
|
62
|
+
subject = 'Your Order is On the Way! 🏍️'
|
|
63
|
+
message = 'Your flowers are on the way! Our rider is heading to your location. 🏍️🌸'
|
|
64
|
+
} else if(status === 'delivered') {
|
|
65
|
+
subject = 'Order Delivered! 🌸'
|
|
66
|
+
message = 'Your flowers have been delivered! We hope you love them. Thank you for choosing Cesar\'s Flower Shop! 🌸'
|
|
67
|
+
}
|
|
54
68
|
|
|
55
69
|
resend.emails.send({
|
|
56
|
-
|
|
70
|
+
from: "Cesar's Flower Shop 🌸 <noreply@cesarsflowershop.com>",
|
|
57
71
|
to: email,
|
|
58
|
-
subject:
|
|
72
|
+
subject: subject,
|
|
59
73
|
html: `
|
|
60
74
|
<h2>Hi ${name}!</h2>
|
|
61
|
-
<p>
|
|
75
|
+
<p> ${message} 🌸</p>
|
|
62
76
|
<br/>
|
|
63
77
|
<p>Thank you for ordering from Cesar's Flower Shop!</p>
|
|
64
78
|
`,
|