Initial commit: backend, storefront, vendor-panel added

This commit is contained in:
2025-08-01 11:05:32 +08:00
commit 08174125d2
2958 changed files with 310810 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
{
"name": "@mercurjs/requests",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"!dist/**/__tests__",
"!dist/**/__mocks__",
"!dist/**/__fixtures__"
],
"engines": {
"node": ">=20"
},
"license": "MIT",
"scripts": {
"build": "rimraf dist && tsc --build",
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
},
"devDependencies": {
"@medusajs/framework": "2.8.6",
"@medusajs/test-utils": "2.8.6",
"@mercurjs/framework": "*",
"@mikro-orm/cli": "6.4.3",
"@mikro-orm/core": "6.4.3",
"@mikro-orm/migrations": "6.4.3",
"@mikro-orm/postgresql": "6.4.3",
"@swc/core": "^1.7.28",
"@swc/jest": "^0.2.36",
"jest": "^29.7.0",
"rimraf": "^3.0.2",
"tsc-alias": "^1.8.6",
"typescript": "^5.6.2"
},
"peerDependencies": {
"@medusajs/framework": "2.8.6",
"@mikro-orm/core": "6.4.3",
"@mikro-orm/migrations": "6.4.3",
"@mikro-orm/postgresql": "6.4.3",
"awilix": "^8.0.1"
}
}

View File

@@ -0,0 +1,11 @@
import { Module } from "@medusajs/framework/utils";
import RequestsModuleService from "./service";
export const REQUESTS_MODULE = "requests";
export { RequestsModuleService };
export * from "./utils";
export default Module(REQUESTS_MODULE, {
service: RequestsModuleService,
});

View File

@@ -0,0 +1,141 @@
{
"namespaces": [
"public"
],
"name": "public",
"tables": [
{
"columns": {
"id": {
"name": "id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"type": {
"name": "type",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"data": {
"name": "data",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
},
"submitter_id": {
"name": "submitter_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"reviewer_id": {
"name": "reviewer_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"reviewer_note": {
"name": "reviewer_note",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"status": {
"name": "status",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "'pending'",
"enumItems": [
"draft",
"pending",
"accepted",
"rejected"
],
"mappedType": "enum"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 6,
"default": "now()",
"mappedType": "datetime"
},
"updated_at": {
"name": "updated_at",
"type": "timestamptz",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 6,
"default": "now()",
"mappedType": "datetime"
},
"deleted_at": {
"name": "deleted_at",
"type": "timestamptz",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"length": 6,
"mappedType": "datetime"
}
},
"name": "request",
"schema": "public",
"indexes": [
{
"keyName": "IDX_request_deleted_at",
"columnNames": [],
"composite": false,
"constraint": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_request_deleted_at\" ON \"request\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "request_pkey",
"columnNames": [
"id"
],
"composite": false,
"constraint": true,
"primary": true,
"unique": true
}
],
"checks": [],
"foreignKeys": {},
"nativeEnums": {}
}
],
"nativeEnums": {}
}

View File

@@ -0,0 +1,14 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20250102142456 extends Migration {
async up(): Promise<void> {
this.addSql('create table if not exists "request" ("id" text not null, "type" text not null, "data" jsonb not null, "submitter_id" text not null, "reviewer_id" text null, "reviewer_note" text null, "status" text check ("status" in (\'pending\', \'accepted\', \'rejected\')) not null default \'pending\', "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "request_pkey" primary key ("id"));');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_request_deleted_at" ON "request" (deleted_at) WHERE deleted_at IS NULL;');
}
async down(): Promise<void> {
this.addSql('drop table if exists "request" cascade;');
}
}

View File

@@ -0,0 +1,17 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20250428150914 extends Migration {
override async up(): Promise<void> {
this.addSql(`alter table if exists "request" drop constraint if exists "request_status_check";`);
this.addSql(`alter table if exists "request" add constraint "request_status_check" check("status" in ('draft', 'pending', 'accepted', 'rejected'));`);
}
override async down(): Promise<void> {
this.addSql(`alter table if exists "request" drop constraint if exists "request_status_check";`);
this.addSql(`alter table if exists "request" add constraint "request_status_check" check("status" in ('pending', 'accepted', 'rejected'));`);
}
}

View File

@@ -0,0 +1 @@
export * from './request'

View File

@@ -0,0 +1,13 @@
import { model } from '@medusajs/framework/utils'
export const Request = model.define('request', {
id: model.id({ prefix: 'req' }).primaryKey(),
type: model.text(),
data: model.json(),
submitter_id: model.text(),
reviewer_id: model.text().nullable(),
reviewer_note: model.text().nullable(),
status: model
.enum(['draft', 'pending', 'accepted', 'rejected'])
.default('pending')
})

View File

@@ -0,0 +1,9 @@
import { MedusaService } from "@medusajs/framework/utils";
import { Request } from "./models";
class RequestsModuleService extends MedusaService({
Request,
}) {}
export default RequestsModuleService;

View File

@@ -0,0 +1 @@
export * from "./notifications";

View File

@@ -0,0 +1,70 @@
import { MedusaContainer } from '@medusajs/framework'
import { ContainerRegistrationKeys, Modules } from '@medusajs/framework/utils'
interface RequestNotificationParams {
container: MedusaContainer
requestId: string
requestType: string
template: string
}
const notificationResources = {
product_type: 'value',
product_category: 'name',
product_collection: 'title',
product_tag: 'value',
product: 'title'
}
export async function sendVendorUIRequestNotification({
container,
requestId,
requestType,
template
}: RequestNotificationParams) {
const notificationService = container.resolve(Modules.NOTIFICATION)
const query = container.resolve(ContainerRegistrationKeys.QUERY)
const {
data: [request]
} = await query.graph({
entity: 'request',
fields: ['*'],
filters: {
id: requestId
}
})
if (!request || request.type !== requestType) {
return
}
const resource = notificationResources[requestType]
const resourceValue = request.data[resource]
const {
data: [member]
} = await query.graph({
entity: 'member',
fields: ['*'],
filters: {
id: request.submitter_id
}
})
if (!member || !member.seller_id) {
return
}
const payload = {}
payload[resource] = resourceValue
await notificationService.createNotifications([
{
to: member.seller_id,
channel: 'seller_feed',
template,
data: { ...payload }
}
])
}

View File

@@ -0,0 +1,27 @@
{
"compilerOptions": {
"lib": ["ES2021"],
"target": "ES2021",
"outDir": "${configDir}/dist",
"esModuleInterop": true,
"declaration": true,
"declarationMap": true,
"noUnusedLocals": true,
"module": "node16",
"moduleResolution": "node16",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitReturns": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"allowJs": true,
"skipLibCheck": true,
"incremental": false
},
"include": ["${configDir}/src"],
"exclude": ["${configDir}/dist", "${configDir}/node_modules"]
}