-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from lxdao-official/develop
Develop
- Loading branch information
Showing
19 changed files
with
324 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- AlterTable | ||
ALTER TABLE "Contribution" ADD COLUMN "endDate" TIMESTAMP(3), | ||
ADD COLUMN "startDate" TIMESTAMP(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- CreateTable | ||
CREATE TABLE "Payment" ( | ||
"id" TEXT NOT NULL, | ||
"purpose" TEXT NOT NULL, | ||
"counterparties" TEXT[], | ||
"category" TEXT NOT NULL, | ||
"chainId" TEXT NOT NULL, | ||
"allocate" TEXT NOT NULL, | ||
"amount" TEXT NOT NULL, | ||
"createAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"deleted" BOOLEAN NOT NULL DEFAULT false, | ||
|
||
CONSTRAINT "Payment_pkey" PRIMARY KEY ("id") | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `projectId` to the `Payment` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Payment" ADD COLUMN "projectId" TEXT NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Payment" ADD CONSTRAINT "Payment_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `symbol` to the `Payment` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Payment" ADD COLUMN "symbol" TEXT NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `crateor` to the `Payment` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Payment" ADD COLUMN "crateor" TEXT NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `crateor` on the `Payment` table. All the data in the column will be lost. | ||
- Added the required column `createor` to the `Payment` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Payment" DROP COLUMN "crateor", | ||
ADD COLUMN "createor" TEXT NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `createor` on the `Payment` table. All the data in the column will be lost. | ||
- Added the required column `creator` to the `Payment` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Payment" DROP COLUMN "createor", | ||
ADD COLUMN "creator" TEXT NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `txHash` to the `Payment` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Payment" ADD COLUMN "txHash" TEXT NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { CoreApiResponse } from '@core/api/coreApiResponse'; | ||
import { CreatePaymentBody, PaymentListQuery } from '@core/type/doc/payment'; | ||
import { Body, Controller, Get, Inject, Post, Query } from '@nestjs/common'; | ||
import { PaymentService } from '@service/payment.service'; | ||
|
||
@Controller('payment') | ||
export class PaymentController { | ||
constructor( | ||
@Inject(PaymentService) | ||
private readonly paymentService: PaymentService, | ||
) {} | ||
|
||
@Get('list') | ||
async getPaymentList(@Query() data: PaymentListQuery) { | ||
const user = await this.paymentService.getPaymentList(data); | ||
return CoreApiResponse.success(user); | ||
} | ||
|
||
@Post('create') | ||
async createPayment(@Body() body: CreatePaymentBody) { | ||
const data = await this.paymentService.createPayment(body); | ||
return CoreApiResponse.success(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Code } from '@core/code'; | ||
import { CreatePaymentBody, PaymentListQuery } from '@core/type/doc/payment'; | ||
import { paginate } from '@core/utils/paginator'; | ||
import { HttpException, Injectable } from '@nestjs/common'; | ||
import { PrismaService } from 'nestjs-prisma'; | ||
|
||
@Injectable() | ||
export class PaymentService { | ||
constructor(private prisma: PrismaService) {} | ||
|
||
async getPaymentList(data: PaymentListQuery) { | ||
const { pageSize, currentPage, projectId } = data; | ||
return paginate( | ||
this.prisma.payment, | ||
{ | ||
where: { | ||
deleted: false, | ||
projectId, | ||
}, | ||
}, | ||
{ | ||
pageSize, | ||
currentPage, | ||
}, | ||
); | ||
} | ||
|
||
async createPayment(body: CreatePaymentBody) { | ||
const { projectId, wallet, ...data } = body; | ||
const project = await this.prisma.project.findFirst({ | ||
where: { | ||
id: projectId, | ||
deleted: false, | ||
}, | ||
}); | ||
if (!project) { | ||
throw new HttpException( | ||
Code.NOT_FOUND_ERROR.message, | ||
Code.NOT_FOUND_ERROR.code, | ||
); | ||
} | ||
const user = await this.prisma.contributor.findFirst({ | ||
where: { | ||
projectId, | ||
wallet, | ||
}, | ||
}); | ||
if (!user) { | ||
throw new HttpException(Code.NO_AUTH.message, Code.NO_AUTH.code); | ||
} | ||
return this.prisma.payment.create({ | ||
data: { | ||
...data, | ||
creator: wallet, | ||
projectId, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.