Skip to content

Commit

Permalink
[starts #187584911] Seller statistics per timeframe (#54)
Browse files Browse the repository at this point in the history
* [starts #187584911] Seller statistics per timeframe

* [finishes #187584911] Seller statistics per timeframe

* Seller-statistics updated
  • Loading branch information
ProgrammerDATCH authored Jun 8, 2024
1 parent 778487e commit 862e4fd
Show file tree
Hide file tree
Showing 30 changed files with 1,618 additions and 870 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Our e-commerce web application server, developed by Team Ninjas, facilitates smo
- Seller create shop Endpoint
- Seller create product Endpoint
- Seller Delete Item Endpoint
- Seller get statistics Endpoint

## TABLE OF API ENDPOINTS SPECIFICATION AND DESCRIPTION

Expand All @@ -58,9 +59,10 @@ Our e-commerce web application server, developed by Team Ninjas, facilitates smo
| 11 | PUT | /api/user/admin-update-role/:id | 200 OK | private | Admin Update role Endpoint |
| 12 | GET | /api/user/admin-get-users | 200 OK | private | Admin get all users Endpoint |
| 13 | GET | /api/user/admin-get-users/:id | 200 OK | private | Admin get one user Endpoint |
| 14 | POST | /api/shop/create-shop | 201 OK | private | Create shop for products |
| 15 | POST | /api/shop/create-product | 201 OK | private | create product in shop |
| 14 | POST | /api/shop/seller-create-shop | 201 OK | private | Create shop for products |
| 15 | POST | /api/shop/seller-create-product | 201 OK | private | create product in shop |
| 16 | DELETE|/api/shop/delete-product/:id | 200 OK | private | Delete Item in Collection |
| 17 | POST | /api/product/seller-statistics | 200 OK | public | Get seller statistics per timeframe |



Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { DataTypes, QueryInterface} from "sequelize";
import { QueryInterface, DataTypes } from "sequelize";

export default {
up: async (queryInterface: QueryInterface, Sequelize: any) => {
export = {
up: async (queryInterface: QueryInterface) => {
await queryInterface.createTable("shops", {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
name: {
allowNull: false,
type: DataTypes.STRING(128)
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
userId: {
allowNull: false,
type: DataTypes.UUID,
allowNull: false,
references: {
model: "users",
key: "id"
},
onDelete: "CASCADE"
onUpdate: "CASCADE"
},
name: {
type: DataTypes.STRING(280),
allowNull: true
},
description: {
type: DataTypes.STRING,
type: DataTypes.STRING(560),
allowNull: true
},
createdAt: {
allowNull: false,
type: DataTypes.DATE,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP")
allowNull: false,
defaultValue: DataTypes.NOW
},
updatedAt: {
allowNull: false,
type: DataTypes.DATE,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP")
allowNull: false,
defaultValue: DataTypes.NOW
}
});
},

down: async (queryInterface: QueryInterface) => {
await queryInterface.dropTable("shops");
}
};
};
42 changes: 42 additions & 0 deletions src/databases/migrations/20240602150804-create-carts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { QueryInterface, DataTypes } from "sequelize";

export = {
up: async (queryInterface: QueryInterface) => {
await queryInterface.createTable("carts", {
id: {
type: DataTypes.UUID,
allowNull: false,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
userId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: "users",
key: "id"
},
onUpdate: "CASCADE",
onDelete: "CASCADE"
},
status: {
type: DataTypes.STRING,
allowNull: false
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
},

down: async (queryInterface: QueryInterface) => {
await queryInterface.dropTable("carts");
}
};
61 changes: 61 additions & 0 deletions src/databases/migrations/20240603150804-create-orders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { QueryInterface, DataTypes } from "sequelize";

export = {
up: async (queryInterface: QueryInterface) => {
await queryInterface.createTable("orders", {
id: {
type: DataTypes.UUID,
allowNull: false,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
shopId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: "shops",
key: "id"
},
onUpdate: "CASCADE",
onDelete: "CASCADE"
},
cartId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: "carts",
key: "id"
},
onUpdate: "CASCADE",
onDelete: "CASCADE"
},
paymentMethodId: {
type: DataTypes.INTEGER,
allowNull: false
},
orderDate: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: DataTypes.NOW
},
status: {
type: DataTypes.STRING,
allowNull: false
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
},

down: async (queryInterface: QueryInterface) => {
await queryInterface.dropTable("orders");
}
};
64 changes: 64 additions & 0 deletions src/databases/migrations/20240607150545-create-cart-products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { QueryInterface, DataTypes } from "sequelize";

export = {
up: async (queryInterface: QueryInterface) => {
await queryInterface.createTable("cart_products", {
id: {
type: DataTypes.UUID,
allowNull: false,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
productId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: "Products",
key: "id"
},
onUpdate: "CASCADE",
onDelete: "CASCADE"
},
cartId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: "carts",
key: "id"
},
onUpdate: "CASCADE",
onDelete: "CASCADE"
},
quantity: {
type: DataTypes.INTEGER,
allowNull: true
},
discount: {
type: DataTypes.FLOAT,
allowNull: true
},
price: {
type: DataTypes.FLOAT,
allowNull: false
},
totalPrice: {
type: DataTypes.FLOAT,
allowNull: false
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
},

down: async (queryInterface: QueryInterface) => {
await queryInterface.dropTable("cart_products");
}
};
63 changes: 63 additions & 0 deletions src/databases/models/cart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable require-jsdoc */
import { Model, DataTypes } from "sequelize";
import sequelizeConnection from "../config/db.config";

export interface CartAttributes {
id: number;
userId: number;
status: string;
createdAt: Date;
updatedAt: Date;
}

class Cart extends Model<CartAttributes> implements CartAttributes {
declare id: number;
declare userId: number;
declare status: string;
declare createdAt: Date;
declare updatedAt: Date;

static associate(models: any) {
Cart.belongsTo(models.User, { foreignKey: "userId", as: "buyer" });
}
}

Cart.init(
{
id: {
type: DataTypes.UUID,
allowNull: false,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
userId: {
type: new DataTypes.UUID,
allowNull: false
},
status: {
type: new DataTypes.STRING,
allowNull: false
},
createdAt: {
field: "createdAt",
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updatedAt: {
field: "updatedAt",
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
},
{
sequelize: sequelizeConnection,
tableName: "carts",
timestamps: true,
modelName: "Cart"
}
);

export default Cart;
Loading

0 comments on commit 862e4fd

Please sign in to comment.