Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8877c04
Added missing packages
clintjeff2 Apr 26, 2025
2223429
Added model for order and orderStatus
clintjeff2 Apr 26, 2025
5f5693b
Added the order module in core modules
clintjeff2 Apr 26, 2025
2184b05
Generate graphql schema
clintjeff2 Apr 26, 2025
1610000
minor changes due to package installation
clintjeff2 Apr 26, 2025
bf96ae1
Succesful generation of migrations new_order
clintjeff2 Apr 26, 2025
44b1b86
Created the create order, update order and update order status dtos
clintjeff2 Apr 26, 2025
2aec2dc
Created the order entity
clintjeff2 Apr 26, 2025
7971121
Created the order service
clintjeff2 Apr 26, 2025
3133796
Created the order resolver
clintjeff2 Apr 26, 2025
437e3a9
Created the order module
clintjeff2 Apr 26, 2025
1926422
Wrote explicit and complete test coverage for order resolver
clintjeff2 Apr 26, 2025
3a25bee
Wrote explicit and complete test coverage for order service
clintjeff2 Apr 26, 2025
d329cb6
updated Order model to map camelCase named fields to snake_case named…
clintjeff2 Apr 27, 2025
2f45f43
Created an updated migration
clintjeff2 Apr 27, 2025
45dd07c
Automatic update on graphql schema
clintjeff2 Apr 27, 2025
9e04425
Changed entity field names to reflect schema in camelCase
clintjeff2 Apr 27, 2025
ae9d4ff
Adjust as neccssary to avoid errorss, due to change in orders schema
clintjeff2 Apr 27, 2025
c3e03a7
Merge branch 'safeswap-order-graphql' of https://github.com/clintjeff…
clintjeff2 Apr 27, 2025
1f10502
Fixed wrong array element placement
clintjeff2 Apr 28, 2025
bad1d41
Fixed wrong prima field names in test case
clintjeff2 Apr 28, 2025
fd4677e
Fixed wrong prima field names in test case
clintjeff2 Apr 28, 2025
6dd5ba1
merged
clintjeff2 Apr 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@
"@nestjs/config": "^4.0.0",
"@nestjs/core": "^11.0.1",
"@nestjs/graphql": "^13.0.2",
"@nestjs/jwt": "^11.0.0",
"@nestjs/mapped-types": "*",
"@nestjs/passport": "^11.0.5",
"@nestjs/platform-express": "^11.0.7",
"@prisma/client": "^6.3.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"graphql": "^16.10.0",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"slugify": "^1.6.6"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Warnings:

- Added the required column `buyer_address` to the `Order` table without a default value. This is not possible if the table is not empty.
- Added the required column `escrow_id` to the `Order` table without a default value. This is not possible if the table is not empty.
- Added the required column `product_id` to the `Order` table without a default value. This is not possible if the table is not empty.
- Added the required column `seller_address` to the `Order` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `Order` table without a default value. This is not possible if the table is not empty.

*/
-- CreateEnum
CREATE TYPE "OrderStatus" AS ENUM ('PENDING', 'ON_DISPUTE', 'FOR_REVIEW', 'APPROVED');

-- AlterTable
ALTER TABLE "Order" ADD COLUMN "buyer_address" TEXT NOT NULL,
ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "escrow_id" TEXT NOT NULL,
ADD COLUMN "product_id" TEXT NOT NULL,
ADD COLUMN "seller_address" TEXT NOT NULL,
ADD COLUMN "status" "OrderStatus" NOT NULL DEFAULT 'PENDING',
ADD COLUMN "updated_at" TIMESTAMP(3) NOT NULL;

-- AddForeignKey
ALTER TABLE "Order" ADD CONSTRAINT "Order_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Warnings:

- You are about to drop the `Order` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "Order" DROP CONSTRAINT "Order_product_id_fkey";

-- DropForeignKey
ALTER TABLE "messages" DROP CONSTRAINT "messages_order_id_fkey";

-- DropTable
DROP TABLE "Order";

-- CreateTable
CREATE TABLE "orders" (
"id" TEXT NOT NULL,
"product_id" TEXT NOT NULL,
"buyer_address" TEXT NOT NULL,
"seller_address" TEXT NOT NULL,
"escrow_id" TEXT NOT NULL,
"status" "OrderStatus" NOT NULL DEFAULT 'PENDING',
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,

CONSTRAINT "orders_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "messages" ADD CONSTRAINT "messages_order_id_fkey" FOREIGN KEY ("order_id") REFERENCES "orders"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "orders" ADD CONSTRAINT "orders_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
26 changes: 22 additions & 4 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ model Product {
sellerAddress String @map("seller_address")
user User @relation(fields: [sellerAddress], references: [walletAddress])
category Category @relation(fields: [categoryId], references: [id])

orders Order[]
@@map("products")
}

Expand Down Expand Up @@ -84,7 +84,25 @@ model Message {
@@map("messages")
}

model Order {
id String @id @default(uuid())
messages Message[]
enum OrderStatus {
PENDING
ON_DISPUTE
FOR_REVIEW
APPROVED
}

model Order {
id String @id @default(uuid())
productId String @map("product_id")
buyerAddress String @map("buyer_address")
sellerAddress String @map("seller_address")
escrowId String @map("escrow_id")
status OrderStatus @default(PENDING)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
messages Message[]

product Product @relation(fields: [productId], references: [id])

@@map("orders")
}
2 changes: 2 additions & 0 deletions apps/backend/src/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { MessageModule } from "../modules/message/message.module";
import { getGraphQLConfig } from "./config/graphql.config";
import { PrismaModule } from "./prisma/prisma.module";

import { OrderModule } from "src/modules/order/order.module";
@Module({
imports: [
AuthModule,
Expand All @@ -31,6 +32,7 @@ import { PrismaModule } from "./prisma/prisma.module";
ProductModule,
ProductImageModule,
UsersModule,
OrderModule,
MessageModule,
],
controllers: [],
Expand Down
36 changes: 36 additions & 0 deletions apps/backend/src/core/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ input CreateMessageInput {
senderAddress: String!
}

input CreateOrderInput {
buyerAddress: String!
escrowId: String!
productId: String!
sellerAddress: String!
status: OrderStatus! = PENDING
}

input CreateProductInput {
categoryId: String!
condition: String!
Expand Down Expand Up @@ -56,13 +64,33 @@ type Message {

type Mutation {
createCategory(data: CreateCategoryInput!): Category!
createOrder(data: CreateOrderInput!): Order!
createProduct(data: CreateProductInput!): ProductDTO!
createProductImage(createProductImage: ProductImageDTO!): ProductImage!
createUser(data: CreateUserInput!): User!
sendMessage(data: CreateMessageInput!): Message!
updateOrderStatus(data: UpdateOrderStatusInput!): Order!
updateUser(data: UpdateUserInput!, walletAddress: String!): User!
}

type Order {
buyerAddress: String!
createdAt: DateTime!
escrowId: String!
id: String!
productId: String!
sellerAddress: String!
status: OrderStatus!
updatedAt: DateTime!
}

enum OrderStatus {
APPROVED
FOR_REVIEW
ON_DISPUTE
PENDING
}

type ProductDTO {

categoryId: String!
Expand Down Expand Up @@ -93,6 +121,9 @@ input ProductImageDTO {
type Query {
categories: [Category!]!
category(id: String!): Category
getOrder(orderId: String!): Order!
getOrdersByBuyer(buyerAddress: String!): [Order!]!
getOrdersBySeller(sellerAddress: String!): [Order!]!
getMessagesByOrder(orderId: String!): [Message!]!
product(id: String!): ProductDTO
productImage(id: String!): ProductImage
Expand All @@ -102,6 +133,11 @@ type Query {
users: [User!]!
}

input UpdateOrderStatusInput {
orderId: String!
status: OrderStatus!
}

input UpdateUserInput {
country: String
email: String
Expand Down
20 changes: 20 additions & 0 deletions apps/backend/src/modules/order/dto/create-order.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { InputType, Field } from '@nestjs/graphql';
import { OrderStatus } from '../entities/order.entity';

@InputType()
export class CreateOrderInput {
@Field()
productId: string;

@Field()
buyerAddress: string;

@Field()
sellerAddress: string;

@Field()
escrowId: string;

@Field(() => OrderStatus, { defaultValue: OrderStatus.PENDING })
status: OrderStatus;
}
11 changes: 11 additions & 0 deletions apps/backend/src/modules/order/dto/update-order-status.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { InputType, Field } from '@nestjs/graphql';
import { OrderStatus } from '../entities/order.entity';

@InputType()
export class UpdateOrderStatusInput {
@Field()
orderId: string;

@Field(() => OrderStatus)
status: OrderStatus;
}
8 changes: 8 additions & 0 deletions apps/backend/src/modules/order/dto/update-order.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CreateOrderInput } from './create-order.input';
import { InputType, Field, Int, PartialType } from '@nestjs/graphql';

@InputType()
export class UpdateOrderInput extends PartialType(CreateOrderInput) {
@Field(() => Int)
id: number;
}
39 changes: 39 additions & 0 deletions apps/backend/src/modules/order/entities/order.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ObjectType, Field, registerEnumType } from '@nestjs/graphql';

export enum OrderStatus {
PENDING = 'PENDING',
ON_DISPUTE = 'ON_DISPUTE',
FOR_REVIEW = 'FOR_REVIEW',
APPROVED = 'APPROVED',
}

registerEnumType(OrderStatus, {
name: 'OrderStatus',
});

@ObjectType()
export class Order {
@Field()
id: string;

@Field()
productId: string;

@Field()
buyerAddress: string;

@Field()
sellerAddress: string;

@Field()
escrowId: string;

@Field(() => OrderStatus)
status: OrderStatus;

@Field()
createdAt: Date;

@Field()
updatedAt: Date;
}
8 changes: 8 additions & 0 deletions apps/backend/src/modules/order/order.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { OrderService } from './order.service';
import { OrderResolver } from './order.resolver';

@Module({
providers: [OrderResolver, OrderService],
})
export class OrderModule {}
Loading
Loading