Compare commits

..

11 Commits

Author SHA1 Message Date
bolade 7b3fd1298d Add order, shipping dock, and transaction routes with CRUD operations and Swagger documentation
- Implemented GET, POST, PUT, and DELETE endpoints for orders, shipping docks, and transactions.
- Added Swagger annotations for API documentation.
- Included error handling for database operations.
- Configured pnpm workspace to ignore built dependencies for sqlite3.
2025-11-12 11:12:05 +01:00
manaknightdigital 1703819bda Merge pull request #2 from emmymayo/master
baas task
2023-12-08 02:06:12 -05:00
Mayowa Emmanuel 7bbafc90a8 baas task 2023-12-07 21:44:21 +00:00
manaknightdigital b640c08c09 Update README.md 2023-12-04 21:28:57 -05:00
manaknightdigital 04a5ae01cf Update README.md 2023-11-21 13:26:44 -05:00
Possible 5485f1af1d Update 2023-11-16 18:50:16 +01:00
ryanwong 7a6da5203e add treeql 2023-05-09 09:33:31 -04:00
manaknightdigital a4177125f8 Update README.md 2022-10-21 12:32:23 -04:00
manaknightdigital 595876509a Merge pull request #1 from To-heeb/master
update of the sequelize link in README of day1 activity to a active doc
2022-10-17 09:28:06 -04:00
Toheeb Oyekola 059da72768 update of the sequelize link in README of day1 activity to a the active doc 2022-10-12 03:05:51 +01:00
Toheeb Oyekola 763aebf1d3 update of the sequelize link in README of day1 activity to a the active doc 2022-10-12 02:55:12 +01:00
19 changed files with 3364 additions and 79 deletions
+1
View File
@@ -0,0 +1 @@
# This project is a toy project for training and quality assurance purposes
+1 -1
View File
@@ -4,7 +4,7 @@
- setup project - setup project
- clone to your github - clone to your github
- Read the documentation https://sequelize.org/v7/manual/getting-started.html - Read the documentation https://sequelize.org/docs/v7/getting-started/
- Setup the following Models in models folder. Make sure tables made by sequelize: - Setup the following Models in models folder. Make sure tables made by sequelize:
``` ```
+134 -20
View File
@@ -1,44 +1,158 @@
var createError = require('http-errors'); var createError = require("http-errors");
var express = require('express'); var express = require("express");
var path = require('path'); var path = require("path");
var cookieParser = require('cookie-parser'); var cookieParser = require("cookie-parser");
var logger = require('morgan'); var logger = require("morgan");
var swaggerJsdoc = require("swagger-jsdoc");
var swaggerUi = require("swagger-ui-express");
var indexRouter = require('./routes/index'); var indexRouter = require("./routes/index");
var usersRouter = require('./routes/users'); var usersRouter = require("./routes/users");
var shippingDockRouter = require("./routes/shipping_dock");
var orderRouter = require("./routes/order");
var transactionRouter = require("./routes/transaction");
const db = require("./models"); const db = require("./models");
var cors = require("cors"); var cors = require("cors");
// Swagger configuration
const swaggerOptions = {
definition: {
openapi: "3.0.0",
info: {
title: "Day 1 API Documentation",
version: "1.0.0",
description:
"API documentation for Shipping Dock, Order, and Transaction management",
},
servers: [
{
url: "http://localhost:3000",
description: "Development server",
},
],
components: {
schemas: {
ShippingDock: {
type: "object",
properties: {
id: {
type: "integer",
description: "Auto-generated ID",
},
name: {
type: "string",
description: "Name of the shipping dock",
},
status: {
type: "integer",
description: "Status: 1 = active, 0 = inactive",
enum: [0, 1],
},
created_at: { type: "string", format: "date-time" },
updated_at: { type: "string", format: "date-time" },
},
},
Order: {
type: "object",
properties: {
id: {
type: "integer",
description: "Auto-generated ID",
},
user_id: { type: "integer", description: "User ID" },
amount: {
type: "number",
format: "decimal",
description: "Order amount",
},
tax: {
type: "number",
format: "decimal",
description: "Tax amount",
},
notes: {
type: "string",
description: "Additional notes",
},
status: {
type: "integer",
description: "Status: 1 = paid, 0 = not paid",
enum: [0, 1],
},
created_at: { type: "string", format: "date-time" },
updated_at: { type: "string", format: "date-time" },
},
},
Transaction: {
type: "object",
properties: {
id: {
type: "integer",
description: "Auto-generated ID",
},
order_id: { type: "integer", description: "Order ID" },
user_id: { type: "integer", description: "User ID" },
shipping_dock_id: {
type: "integer",
description: "Shipping Dock ID",
},
amount: {
type: "number",
format: "decimal",
description: "Transaction amount",
},
notes: {
type: "string",
description: "Additional notes",
},
created_at: { type: "string", format: "date-time" },
updated_at: { type: "string", format: "date-time" },
},
},
},
},
},
apis: ["./routes/*.js"],
};
const swaggerSpec = swaggerJsdoc(swaggerOptions);
var app = express(); var app = express();
app.set("db", db); app.set("db", db);
// view engine setup // view engine setup
app.set('views', path.join(__dirname, 'views')); app.set("views", path.join(__dirname, "views"));
app.set('view engine', 'jade'); app.set("view engine", "jade");
app.use(cors()); app.use(cors());
app.use(logger('dev')); app.use(logger("dev"));
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({ extended: false })); app.use(express.urlencoded({ extended: false }));
app.use(cookieParser()); app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, "public")));
app.use('/', indexRouter); // Swagger docs route
app.use('/users', usersRouter); app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.use("/", indexRouter);
app.use("/users", usersRouter);
app.use("/api/v1/shipping_dock", shippingDockRouter);
app.use("/api/v1/order", orderRouter);
app.use("/api/v1/transaction", transactionRouter);
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use(function (req, res, next) { app.use(function (req, res, next) {
next(createError(404)); next(createError(404));
}); });
// error handler // error handler
app.use(function (err, req, res, next) { app.use(function (err, req, res, next) {
// set locals, only providing error in development // set locals, only providing error in development
res.locals.message = err.message; res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {}; res.locals.error = req.app.get("env") === "development" ? err : {};
// render the error page // render the error page
res.status(err.status || 500); res.status(err.status || 500);
res.render('error'); res.render("error");
}); });
module.exports = app; module.exports = app;
Binary file not shown.
+39 -45
View File
@@ -1,4 +1,4 @@
'use strict'; "use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2020*/ /*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2020*/
/** /**
* Sequelize File * Sequelize File
@@ -8,62 +8,56 @@
* @author Ryan Wong * @author Ryan Wong
* *
*/ */
const fs = require('fs'); const fs = require("fs");
const path = require('path'); const path = require("path");
let Sequelize = require('sequelize'); let Sequelize = require("sequelize");
const basename = path.basename(__filename); const basename = path.basename(__filename);
const { DataTypes } = require('sequelize'); const { DataTypes } = require("sequelize");
const config = {
DB_DATABASE: 'mysql',
DB_USERNAME: 'root',
DB_PASSWORD: 'root',
DB_ADAPTER: 'mysql',
DB_NAME: 'day_1',
DB_HOSTNAME: 'localhost',
DB_PORT: 3306,
};
let db = {}; let db = {};
let sequelize = new Sequelize(config.DB_DATABASE, config.DB_USERNAME, config.DB_PASSWORD, { // SQLite configuration - stores data in a file instead of MySQL server
dialect: config.DB_ADAPTER, let sequelize = new Sequelize({
username: config.DB_USERNAME, dialect: "sqlite",
password: config.DB_PASSWORD, storage: "./database.sqlite", // Database file location
database: config.DB_NAME, logging: console.log,
host: config.DB_HOSTNAME, define: {
port: config.DB_PORT, timestamps: false,
logging: console.log, underscoredAll: true,
timezone: '-04:00', underscored: true,
pool: { },
maxConnections: 1,
minConnections: 0,
maxIdleTime: 100,
},
define: {
timestamps: false,
underscoredAll: true,
underscored: true,
},
}); });
// sequelize.sync({ force: true }); // Sync database tables
sequelize
.sync({ alter: true })
.then(() => {
console.log("Database tables synchronized");
})
.catch((err) => {
console.error("Error synchronizing database:", err);
});
fs.readdirSync(__dirname) fs.readdirSync(__dirname)
.filter((file) => { .filter((file) => {
return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js'; return (
}) file.indexOf(".") !== 0 &&
.forEach((file) => { file !== basename &&
var model = require(path.join(__dirname, file))(sequelize, DataTypes); file.slice(-3) === ".js"
db[model.name] = model; );
}); })
.forEach((file) => {
var model = require(path.join(__dirname, file))(sequelize, DataTypes);
db[model.name] = model;
});
Object.keys(db).forEach((modelName) => { Object.keys(db).forEach((modelName) => {
if (db[modelName].associate) { if (db[modelName].associate) {
db[modelName].associate(db); db[modelName].associate(db);
} }
}); });
db.sequelize = sequelize; db.sequelize = sequelize;
db.Sequelize = Sequelize; db.Sequelize = Sequelize;
module.exports = db; module.exports = db;
+45
View File
@@ -0,0 +1,45 @@
module.exports = (sequelize, DataTypes) => {
const order = sequelize.define(
"order",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
amount: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
},
tax: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
},
notes: {
type: DataTypes.TEXT,
allowNull: true,
},
status: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: "1: paid, 0: not paid",
},
created_at: DataTypes.DATE,
updated_at: DataTypes.DATE,
},
{
timestamps: true,
freezeTableName: true,
tableName: "order",
createdAt: "created_at",
updatedAt: "updated_at",
}
);
return order;
};
+33
View File
@@ -0,0 +1,33 @@
module.exports = (sequelize, DataTypes) => {
const shipping_dock = sequelize.define(
"shipping_dock",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
status: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 1,
comment: "1: active, 0: inactive",
},
created_at: DataTypes.DATE,
updated_at: DataTypes.DATE,
},
{
timestamps: true,
freezeTableName: true,
tableName: "shipping_dock",
createdAt: "created_at",
updatedAt: "updated_at",
}
);
return shipping_dock;
};
+43
View File
@@ -0,0 +1,43 @@
module.exports = (sequelize, DataTypes) => {
const transaction = sequelize.define(
"transaction",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
order_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
user_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
shipping_dock_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
amount: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
},
notes: {
type: DataTypes.TEXT,
allowNull: true,
},
created_at: DataTypes.DATE,
updated_at: DataTypes.DATE,
},
{
timestamps: true,
freezeTableName: true,
tableName: "transaction",
createdAt: "created_at",
updatedAt: "updated_at",
}
);
return transaction;
};
+4 -1
View File
@@ -14,6 +14,9 @@
"jade": "~1.11.0", "jade": "~1.11.0",
"morgan": "~1.9.1", "morgan": "~1.9.1",
"mysql2": "^2.3.3", "mysql2": "^2.3.3",
"sequelize": "^6.15.1" "sequelize": "^6.15.1",
"sqlite3": "^5.1.7",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1"
} }
} }
+2245
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -0,0 +1,2 @@
ignoredBuiltDependencies:
- sqlite3
+259
View File
@@ -0,0 +1,259 @@
var express = require("express");
var router = express.Router();
/**
* @swagger
* /api/v1/order:
* get:
* summary: Get all orders
* tags: [Order]
* responses:
* 200:
* description: List of all orders
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: array
* items:
* $ref: '#/components/schemas/Order'
*/
// GET all orders
router.get("/", async function (req, res, next) {
try {
const db = req.app.get("db");
const orders = await db.order.findAll();
res.json({ success: true, data: orders });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error fetching orders",
error: error.message,
});
}
});
/**
* @swagger
* /api/v1/order/{id}:
* get:
* summary: Get one order by ID
* tags: [Order]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* responses:
* 200:
* description: Order details
* 404:
* description: Order not found
*/
// GET one order by id
router.get("/:id", async function (req, res, next) {
try {
const db = req.app.get("db");
const order = await db.order.findByPk(req.params.id);
if (!order) {
return res
.status(404)
.json({ success: false, message: "Order not found" });
}
res.json({ success: true, data: order });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error fetching order",
error: error.message,
});
}
});
/**
* @swagger
* /api/v1/order:
* post:
* summary: Create a new order
* tags: [Order]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - user_id
* - amount
* - tax
* properties:
* user_id:
* type: integer
* amount:
* type: number
* format: decimal
* tax:
* type: number
* format: decimal
* notes:
* type: string
* status:
* type: integer
* enum: [0, 1]
* default: 0
* description: 0 = not paid, 1 = paid
* responses:
* 201:
* description: Order created successfully
* 400:
* description: Bad request
*/
// POST - Create a new order
router.post("/", async function (req, res, next) {
try {
const db = req.app.get("db");
const { user_id, amount, tax, notes, status } = req.body;
if (!user_id || !amount || tax === undefined) {
return res.status(400).json({
success: false,
message: "user_id, amount, and tax are required",
});
}
const order = await db.order.create({
user_id,
amount,
tax,
notes: notes || null,
status: status !== undefined ? status : 0,
});
res.status(201).json({ success: true, data: order });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error creating order",
error: error.message,
});
}
});
/**
* @swagger
* /api/v1/order/{id}:
* put:
* summary: Update an order by ID
* tags: [Order]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* requestBody:
* content:
* application/json:
* schema:
* type: object
* properties:
* user_id:
* type: integer
* amount:
* type: number
* tax:
* type: number
* notes:
* type: string
* status:
* type: integer
* enum: [0, 1]
* responses:
* 200:
* description: Order updated successfully
* 404:
* description: Order not found
* delete:
* summary: Delete an order by ID
* tags: [Order]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* responses:
* 200:
* description: Order deleted successfully
* 404:
* description: Order not found
*/
// PUT - Update an order by id
router.put("/:id", async function (req, res, next) {
try {
const db = req.app.get("db");
const { user_id, amount, tax, notes, status } = req.body;
const order = await db.order.findByPk(req.params.id);
if (!order) {
return res
.status(404)
.json({ success: false, message: "Order not found" });
}
await order.update({
user_id: user_id !== undefined ? user_id : order.user_id,
amount: amount !== undefined ? amount : order.amount,
tax: tax !== undefined ? tax : order.tax,
notes: notes !== undefined ? notes : order.notes,
status: status !== undefined ? status : order.status,
});
res.json({ success: true, data: order });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error updating order",
error: error.message,
});
}
});
// DELETE - Delete an order by id
router.delete("/:id", async function (req, res, next) {
try {
const db = req.app.get("db");
const order = await db.order.findByPk(req.params.id);
if (!order) {
return res
.status(404)
.json({ success: false, message: "Order not found" });
}
await order.destroy();
res.json({ success: true, message: "Order deleted successfully" });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error deleting order",
error: error.message,
});
}
});
module.exports = router;
+257
View File
@@ -0,0 +1,257 @@
var express = require("express");
var router = express.Router();
/**
* @swagger
* /api/v1/shipping_dock:
* get:
* summary: Get all shipping docks
* tags: [Shipping Dock]
* responses:
* 200:
* description: List of all shipping docks
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: array
* items:
* $ref: '#/components/schemas/ShippingDock'
*/
// GET all shipping docks
router.get("/", async function (req, res, next) {
try {
const db = req.app.get("db");
const shippingDocks = await db.shipping_dock.findAll();
res.json({ success: true, data: shippingDocks });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error fetching shipping docks",
error: error.message,
});
}
});
/**
* @swagger
* /api/v1/shipping_dock/{id}:
* get:
* summary: Get one shipping dock by ID
* tags: [Shipping Dock]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* description: Shipping dock ID
* responses:
* 200:
* description: Shipping dock details
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* $ref: '#/components/schemas/ShippingDock'
* 404:
* description: Shipping dock not found
*/
// GET one shipping dock by id
router.get("/:id", async function (req, res, next) {
try {
const db = req.app.get("db");
const shippingDock = await db.shipping_dock.findByPk(req.params.id);
if (!shippingDock) {
return res
.status(404)
.json({ success: false, message: "Shipping dock not found" });
}
res.json({ success: true, data: shippingDock });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error fetching shipping dock",
error: error.message,
});
}
});
/**
* @swagger
* /api/v1/shipping_dock:
* post:
* summary: Create a new shipping dock
* tags: [Shipping Dock]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - name
* properties:
* name:
* type: string
* description: Name of the shipping dock
* status:
* type: integer
* description: Status (1 = active, 0 = inactive)
* enum: [0, 1]
* default: 1
* responses:
* 201:
* description: Shipping dock created successfully
* 400:
* description: Bad request - missing required fields
*/
// POST - Create a new shipping dock
router.post("/", async function (req, res, next) {
try {
const db = req.app.get("db");
const { name, status } = req.body;
if (!name) {
return res
.status(400)
.json({ success: false, message: "Name is required" });
}
const shippingDock = await db.shipping_dock.create({
name,
status: status !== undefined ? status : 1,
});
res.status(201).json({ success: true, data: shippingDock });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error creating shipping dock",
error: error.message,
});
}
});
/**
* @swagger
* /api/v1/shipping_dock/{id}:
* put:
* summary: Update a shipping dock by ID
* tags: [Shipping Dock]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* description: Shipping dock ID
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* name:
* type: string
* status:
* type: integer
* enum: [0, 1]
* responses:
* 200:
* description: Shipping dock updated successfully
* 404:
* description: Shipping dock not found
*/
// PUT - Update a shipping dock by id
router.put("/:id", async function (req, res, next) {
try {
const db = req.app.get("db");
const { name, status } = req.body;
const shippingDock = await db.shipping_dock.findByPk(req.params.id);
if (!shippingDock) {
return res
.status(404)
.json({ success: false, message: "Shipping dock not found" });
}
await shippingDock.update({
name: name !== undefined ? name : shippingDock.name,
status: status !== undefined ? status : shippingDock.status,
});
res.json({ success: true, data: shippingDock });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error updating shipping dock",
error: error.message,
});
}
});
/**
* @swagger
* /api/v1/shipping_dock/{id}:
* delete:
* summary: Delete a shipping dock by ID
* tags: [Shipping Dock]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* description: Shipping dock ID
* responses:
* 200:
* description: Shipping dock deleted successfully
* 404:
* description: Shipping dock not found
*/
// DELETE - Delete a shipping dock by id
router.delete("/:id", async function (req, res, next) {
try {
const db = req.app.get("db");
const shippingDock = await db.shipping_dock.findByPk(req.params.id);
if (!shippingDock) {
return res
.status(404)
.json({ success: false, message: "Shipping dock not found" });
}
await shippingDock.destroy();
res.json({
success: true,
message: "Shipping dock deleted successfully",
});
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error deleting shipping dock",
error: error.message,
});
}
});
module.exports = router;
+262
View File
@@ -0,0 +1,262 @@
var express = require("express");
var router = express.Router();
/**
* @swagger
* /api/v1/transaction:
* get:
* summary: Get all transactions
* tags: [Transaction]
* responses:
* 200:
* description: List of all transactions
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: array
* items:
* $ref: '#/components/schemas/Transaction'
*/
// GET all transactions
router.get("/", async function (req, res, next) {
try {
const db = req.app.get("db");
const transactions = await db.transaction.findAll();
res.json({ success: true, data: transactions });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error fetching transactions",
error: error.message,
});
}
});
/**
* @swagger
* /api/v1/transaction/{id}:
* get:
* summary: Get one transaction by ID
* tags: [Transaction]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* responses:
* 200:
* description: Transaction details
* 404:
* description: Transaction not found
*/
// GET one transaction by id
router.get("/:id", async function (req, res, next) {
try {
const db = req.app.get("db");
const transaction = await db.transaction.findByPk(req.params.id);
if (!transaction) {
return res
.status(404)
.json({ success: false, message: "Transaction not found" });
}
res.json({ success: true, data: transaction });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error fetching transaction",
error: error.message,
});
}
});
/**
* @swagger
* /api/v1/transaction:
* post:
* summary: Create a new transaction
* tags: [Transaction]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - order_id
* - user_id
* - shipping_dock_id
* - amount
* properties:
* order_id:
* type: integer
* user_id:
* type: integer
* shipping_dock_id:
* type: integer
* amount:
* type: number
* format: decimal
* notes:
* type: string
* responses:
* 201:
* description: Transaction created successfully
* 400:
* description: Bad request
*/
// POST - Create a new transaction
router.post("/", async function (req, res, next) {
try {
const db = req.app.get("db");
const { order_id, user_id, shipping_dock_id, amount, notes } = req.body;
if (!order_id || !user_id || !shipping_dock_id || !amount) {
return res.status(400).json({
success: false,
message:
"order_id, user_id, shipping_dock_id, and amount are required",
});
}
const transaction = await db.transaction.create({
order_id,
user_id,
shipping_dock_id,
amount,
notes: notes || null,
});
res.status(201).json({ success: true, data: transaction });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error creating transaction",
error: error.message,
});
}
});
/**
* @swagger
* /api/v1/transaction/{id}:
* put:
* summary: Update a transaction by ID
* tags: [Transaction]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* requestBody:
* content:
* application/json:
* schema:
* type: object
* properties:
* order_id:
* type: integer
* user_id:
* type: integer
* shipping_dock_id:
* type: integer
* amount:
* type: number
* notes:
* type: string
* responses:
* 200:
* description: Transaction updated successfully
* 404:
* description: Transaction not found
* delete:
* summary: Delete a transaction by ID
* tags: [Transaction]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* responses:
* 200:
* description: Transaction deleted successfully
* 404:
* description: Transaction not found
*/
// PUT - Update a transaction by id
router.put("/:id", async function (req, res, next) {
try {
const db = req.app.get("db");
const { order_id, user_id, shipping_dock_id, amount, notes } = req.body;
const transaction = await db.transaction.findByPk(req.params.id);
if (!transaction) {
return res
.status(404)
.json({ success: false, message: "Transaction not found" });
}
await transaction.update({
order_id: order_id !== undefined ? order_id : transaction.order_id,
user_id: user_id !== undefined ? user_id : transaction.user_id,
shipping_dock_id:
shipping_dock_id !== undefined
? shipping_dock_id
: transaction.shipping_dock_id,
amount: amount !== undefined ? amount : transaction.amount,
notes: notes !== undefined ? notes : transaction.notes,
});
res.json({ success: true, data: transaction });
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error updating transaction",
error: error.message,
});
}
});
// DELETE - Delete a transaction by id
router.delete("/:id", async function (req, res, next) {
try {
const db = req.app.get("db");
const transaction = await db.transaction.findByPk(req.params.id);
if (!transaction) {
return res
.status(404)
.json({ success: false, message: "Transaction not found" });
}
await transaction.destroy();
res.json({
success: true,
message: "Transaction deleted successfully",
});
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Error deleting transaction",
error: error.message,
});
}
});
module.exports = router;
+1 -6
View File
@@ -3,9 +3,4 @@
## Instructions ## Instructions
- setup project - setup project
- clone to your github - implement https://www.treeql.org/ manually
- Open figma file https://www.figma.com/file/Zr1EutaLsykPcADfC3el7r/ai-marketing-site-sample?node-id=0%3A1
- Need you to finish the site by end of day both mobile and desktop responsive
- Use bootstrap 4
- CSS should be clean, not using inline style CSS but proper classes
- deploy site using github pages https://www.codecademy.com/articles/f1-u3-github-pages
+6 -4
View File
@@ -2,7 +2,9 @@
## Instructions ## Instructions
- setup project - Setup project
- clone to your github - Clone to your github
- Make the frontend for this project https://www.figma.com/file/iaKhmTAN28YiYXAOZAr9rN/Scheduler-Task?node-id=0%3A1 - Check this https://www.figma.com/file/iaKhmTAN28YiYXAOZAr9rN/Scheduler-Task?node-id=0%3A1
- timezones are generated dynamically - Convert it into ejs/eta.
- Timezones should be generated dynamically
- Make a book schedule API like calendly.
+30 -1
View File
@@ -1 +1,30 @@
Continue day 19 if not done # Day 20
Read:
- https://www.notion.so/How-to-Use-Baas-00f549dda3a84dc48b352c79222f1a3a
- https://www.notion.so/Create-Manage-Projects-With-Wireframe-Tool-df67b882f0c14735a0192d69dc3ff777
- Request for Wireframe tool url from Project Manager.
1. login to Wireframe tool. Create SOW and Wireframe called <name-inventory>.
2. Navigate to Wireframe side-menu click, Edit > Setting, create a project (<name-inventory>) from here according to specifications of wireframe document provided (inventory-app.pdf).
3. Create Models. Switch to Models tab or Web/React tab (Manage Models).
4. Create Roles and set Permissions. (Web/React Tab > Manage Permissions).
5. Create React portal and marketing pages and then export React. (Web/React Tab).
6. Create Custom APIs and commit. (API tab). API code would be commited to http://23.29.118.76:3000/mkdlabs/<name-inventory_backend>.git
7. Switch to Deployment Tab. Initialize deployment and create repositories.
8. Setup BAAS locally. Clone http://23.29.118.76:3000/mkdlabs/mkd_baas.git
9. npm install and request for config from Project Manager.
10. Clone backend repo on src/backend/custom
11. Write APIs, and test locally.
Binary file not shown.
+2 -1
View File
@@ -54,7 +54,8 @@ DELETE /api/v1/user/:id (delete one)
``` ```
1.Loop through all active users 1.Loop through all active users
2.Loop through all odd id emails if today is monday, wednesday, friday. Otherwise do all even id for other days. 2.Loop through all odd id emails if today is monday, wednesday, friday. Otherwise do all even id for other days.
3.Write into email queue what email to send from step 2. Set status as not sent. Set send_at as next day. 4.Loop through all the users in user table and make a table of user_id.
3.Write into email queue for each user in step 2 (so if 3 total emails, 2 ids are odd, say there 5 users so on monday you add 2 x 5 = 10 emails into email_queue.) what email to send from step 2. Set status as not sent. Set send_at as next day.
``` ```
- create a cronjob called email_sending.js in cronjob folder - create a cronjob called email_sending.js in cronjob folder