From 3257f4bf216bb031186bb0541979c84808b71e77 Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 16:39:51 +0800 Subject: [PATCH 01/14] feat: update prisma --- prisma/migrations/20240220083932_2_20/migration.sql | 3 +++ prisma/schema.prisma | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 prisma/migrations/20240220083932_2_20/migration.sql diff --git a/prisma/migrations/20240220083932_2_20/migration.sql b/prisma/migrations/20240220083932_2_20/migration.sql new file mode 100644 index 0000000..4f83587 --- /dev/null +++ b/prisma/migrations/20240220083932_2_20/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "Contribution" ADD COLUMN "endDate" TIMESTAMP(3), +ADD COLUMN "startDate" TIMESTAMP(3); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 1e026ce..98ae62a 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -73,6 +73,8 @@ model Contribution { projectId String type String[] contributionDate String? + startDate DateTime? + endDate DateTime? createAt DateTime @default(now()) updatedAt DateTime @updatedAt deleted Boolean @default(false) From f4aa6545b30d8cc837f976d8176b413399d623cd Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 17:23:10 +0800 Subject: [PATCH 02/14] feat: createContribution api add params --- src/core/service/contribution.service.ts | 6 ++++-- src/core/type/doc/contribution.ts | 13 ++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/core/service/contribution.service.ts b/src/core/service/contribution.service.ts index f4512a5..657aac4 100644 --- a/src/core/service/contribution.service.ts +++ b/src/core/service/contribution.service.ts @@ -162,7 +162,8 @@ export class ContributionService { credit, operatorId, type, - contributionDate, + startDate, + endDate, } = body; const project = await this.prisma.project.findFirst({ where: { @@ -194,7 +195,8 @@ export class ContributionService { credit, projectId, type, - contributionDate, + startDate: new Date(startDate), + endDate: new Date(endDate), ownerId: operatorId, id, }, diff --git a/src/core/type/doc/contribution.ts b/src/core/type/doc/contribution.ts index 593877b..e7554b9 100644 --- a/src/core/type/doc/contribution.ts +++ b/src/core/type/doc/contribution.ts @@ -67,9 +67,16 @@ export class CreateContributionBody extends AuthBody { type: string[]; @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - contributionDate: string; + @IsNumber() + @Type(() => Number) + @ApiProperty({ type: 'number' }) + startDate: number; + + @IsNotEmpty() + @IsNumber() + @Type(() => Number) + @ApiProperty({ type: 'number' }) + endDate: number; } export class PrepareClaimBody { From 630cd0b9956b8b4f6e40a3eb4e7612afe5d1a980 Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 17:38:07 +0800 Subject: [PATCH 03/14] feat: add payment table --- .../20240220093751_payment/migration.sql | 15 +++++++++++++++ prisma/schema.prisma | 13 +++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 prisma/migrations/20240220093751_payment/migration.sql diff --git a/prisma/migrations/20240220093751_payment/migration.sql b/prisma/migrations/20240220093751_payment/migration.sql new file mode 100644 index 0000000..80a9a16 --- /dev/null +++ b/prisma/migrations/20240220093751_payment/migration.sql @@ -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") +); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 98ae62a..a866e85 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -120,3 +120,16 @@ model MintReocrd { updatedAt DateTime @updatedAt deleted Boolean @default(false) } + +model Payment { + id String @id @default(uuid()) + purpose String + counterparties String[] + category String + chainId String + allocate String + amount String + createAt DateTime @default(now()) + updatedAt DateTime @updatedAt + deleted Boolean @default(false) +} From a9fb15466282e137bf99c166f67636d4d158fc48 Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 17:44:39 +0800 Subject: [PATCH 04/14] feat: add payment table --- .../migrations/20240220093844_payment1/migration.sql | 11 +++++++++++ prisma/schema.prisma | 3 +++ 2 files changed, 14 insertions(+) create mode 100644 prisma/migrations/20240220093844_payment1/migration.sql diff --git a/prisma/migrations/20240220093844_payment1/migration.sql b/prisma/migrations/20240220093844_payment1/migration.sql new file mode 100644 index 0000000..31225e6 --- /dev/null +++ b/prisma/migrations/20240220093844_payment1/migration.sql @@ -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; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index a866e85..e0f89bc 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -42,6 +42,7 @@ model Project { contributors Contributor[] MintReocrd MintReocrd[] ContributionType ContributionType[] + Payment Payment[] } model User { @@ -129,6 +130,8 @@ model Payment { chainId String allocate String amount String + project Project @relation(fields: [projectId], references: [id]) + projectId String createAt DateTime @default(now()) updatedAt DateTime @updatedAt deleted Boolean @default(false) From 45f2393b6f724c7a605c34d30faf7bb12880f7d1 Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 17:44:49 +0800 Subject: [PATCH 05/14] feat: add payment api type --- src/core/type/doc/payment.ts | 173 +++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 src/core/type/doc/payment.ts diff --git a/src/core/type/doc/payment.ts b/src/core/type/doc/payment.ts new file mode 100644 index 0000000..15a5671 --- /dev/null +++ b/src/core/type/doc/payment.ts @@ -0,0 +1,173 @@ +import { Contributor } from '@core/type/contributor'; +import { AuthBody } from '@core/type/doc/auth'; +import { PaginateQuery } from '@core/type/doc/common'; +import { ApiProperty } from '@nestjs/swagger'; +import { VoteApprove, VoteSystem } from '@prisma/client'; +import { Type } from 'class-transformer'; +import { + ArrayNotEmpty, + IsArray, + IsEnum, + IsNotEmpty, + IsNumber, + IsOptional, + IsString, + ValidateNested, +} from 'class-validator'; + +export enum VoteSystemEnum { + EQUAL = 'EQUAL', + WEIGHT = 'WEIGHT', +} + +export enum VoteApproveEnum { + DEFAULT = 'DEFAULT', + RELATIVE2 = 'RELATIVE2', + ABSOLUTE1 = 'ABSOLUTE1', + ABSOLUTE2 = 'ABSOLUTE2', +} + +export class CreateProjectBody { + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + name: string; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + address: string; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + symbol: string; + + @IsOptional() + @IsString() + @ApiProperty({ type: 'string' }) + pointConsensus: string; + + @IsNotEmpty() + @IsNumber() + @Type(() => Number) + @ApiProperty({ type: 'number' }) + network: number; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + votePeriod: string; + + @ArrayNotEmpty() + @IsArray() + @ValidateNested({ each: true }) + @ApiProperty({ isArray: true }) + contributors: Contributor[]; + + @IsOptional() + @IsString() + @ApiProperty({ type: 'string', required: false }) + logo: string; + + @IsOptional() + @IsString() + @ApiProperty({ type: 'string', required: false }) + intro: string; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + @IsEnum(VoteSystemEnum) + voteSystem: VoteSystem; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + @IsEnum(VoteApproveEnum) + voteApprove: VoteApprove; + + @IsNotEmpty() + @IsNumber() + @Type(() => Number) + @ApiProperty({ type: 'number' }) + voteThreshold: number; +} + +export class UpdateProjectBody extends AuthBody { + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + name: string; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + votePeriod: string; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + logo: string; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + intro: string; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + @IsEnum(VoteSystem) + voteSystem: VoteSystem; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + @IsEnum(VoteApprove) + voteApprove: VoteApprove; + + @IsNotEmpty() + @IsNumber() + @Type(() => Number) + @ApiProperty({ type: 'number' }) + voteThreshold: number; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + rule: string; +} + +export class PaymentListQuery extends PaginateQuery { + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + projectId: string; +} + +export class CreateContributionTypeBody { + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + name: string; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + color: string; +} + +export class UpdateContributionTypeBody extends CreateContributionTypeBody { + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + id: string; +} + +export class DeleteContributionTypeBody { + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + id: string; +} From 8dc21500cf1b07a1c9f9f5a1d5ee8c8bf12d854a Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 17:44:56 +0800 Subject: [PATCH 06/14] feat: add getPaymentList api --- src/controller/payment.controller.ts | 19 +++++++++++++++++++ src/core/service/payment.service.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/controller/payment.controller.ts create mode 100644 src/core/service/payment.service.ts diff --git a/src/controller/payment.controller.ts b/src/controller/payment.controller.ts new file mode 100644 index 0000000..0d94bb8 --- /dev/null +++ b/src/controller/payment.controller.ts @@ -0,0 +1,19 @@ +import { CoreApiResponse } from '@core/api/coreApiResponse'; +import { PaymentListQuery } from '@core/type/doc/payment'; +import { Controller, Get, Inject, Query } from '@nestjs/common'; +import { PaymentService } from '@service/payment.service'; +import { UserService } from '@service/user.service'; + +@Controller('payment') +export class UserController { + constructor( + @Inject(UserService) + private readonly paymentService: PaymentService, + ) {} + + @Get('list') + async getPaymentList(@Query() data: PaymentListQuery) { + const user = await this.paymentService.getPaymentList(data); + return CoreApiResponse.success(user); + } +} diff --git a/src/core/service/payment.service.ts b/src/core/service/payment.service.ts new file mode 100644 index 0000000..519219e --- /dev/null +++ b/src/core/service/payment.service.ts @@ -0,0 +1,26 @@ +import { PaymentListQuery } from '@core/type/doc/payment'; +import { paginate } from '@core/utils/paginator'; +import { 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, + }, + ); + } +} From 2fd55dfa75dea5e85fde97d19fe7ed6d1c49b669 Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 18:02:55 +0800 Subject: [PATCH 07/14] feat: update payment schema --- prisma/migrations/20240220095207_payment2/migration.sql | 8 ++++++++ prisma/schema.prisma | 1 + 2 files changed, 9 insertions(+) create mode 100644 prisma/migrations/20240220095207_payment2/migration.sql diff --git a/prisma/migrations/20240220095207_payment2/migration.sql b/prisma/migrations/20240220095207_payment2/migration.sql new file mode 100644 index 0000000..e367f00 --- /dev/null +++ b/prisma/migrations/20240220095207_payment2/migration.sql @@ -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; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e0f89bc..e933d34 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -129,6 +129,7 @@ model Payment { category String chainId String allocate String + symbol String amount String project Project @relation(fields: [projectId], references: [id]) projectId String From d547aabbb03c8f3e65c0a29aa73d163b91dd0462 Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 18:03:01 +0800 Subject: [PATCH 08/14] feat: add createPayment api --- src/controller/payment.controller.ts | 10 +- src/core/service/payment.service.ts | 36 ++++++- src/core/type/doc/payment.ts | 146 +++------------------------ 3 files changed, 55 insertions(+), 137 deletions(-) diff --git a/src/controller/payment.controller.ts b/src/controller/payment.controller.ts index 0d94bb8..ed4fbfa 100644 --- a/src/controller/payment.controller.ts +++ b/src/controller/payment.controller.ts @@ -1,6 +1,6 @@ import { CoreApiResponse } from '@core/api/coreApiResponse'; -import { PaymentListQuery } from '@core/type/doc/payment'; -import { Controller, Get, Inject, Query } from '@nestjs/common'; +import { CreatePaymentBody, PaymentListQuery } from '@core/type/doc/payment'; +import { Body, Controller, Get, Inject, Post, Query } from '@nestjs/common'; import { PaymentService } from '@service/payment.service'; import { UserService } from '@service/user.service'; @@ -16,4 +16,10 @@ export class UserController { 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); + } } diff --git a/src/core/service/payment.service.ts b/src/core/service/payment.service.ts index 519219e..7e0b645 100644 --- a/src/core/service/payment.service.ts +++ b/src/core/service/payment.service.ts @@ -1,6 +1,7 @@ -import { PaymentListQuery } from '@core/type/doc/payment'; +import { Code } from '@core/code'; +import { CreatePaymentBody, PaymentListQuery } from '@core/type/doc/payment'; import { paginate } from '@core/utils/paginator'; -import { Injectable } from '@nestjs/common'; +import { HttpException, Injectable } from '@nestjs/common'; import { PrismaService } from 'nestjs-prisma'; @Injectable() @@ -23,4 +24,35 @@ export class PaymentService { }, ); } + + 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, + projectId, + }, + }); + } } diff --git a/src/core/type/doc/payment.ts b/src/core/type/doc/payment.ts index 15a5671..6270799 100644 --- a/src/core/type/doc/payment.ts +++ b/src/core/type/doc/payment.ts @@ -1,142 +1,48 @@ -import { Contributor } from '@core/type/contributor'; import { AuthBody } from '@core/type/doc/auth'; import { PaginateQuery } from '@core/type/doc/common'; import { ApiProperty } from '@nestjs/swagger'; -import { VoteApprove, VoteSystem } from '@prisma/client'; -import { Type } from 'class-transformer'; -import { - ArrayNotEmpty, - IsArray, - IsEnum, - IsNotEmpty, - IsNumber, - IsOptional, - IsString, - ValidateNested, -} from 'class-validator'; - -export enum VoteSystemEnum { - EQUAL = 'EQUAL', - WEIGHT = 'WEIGHT', -} - -export enum VoteApproveEnum { - DEFAULT = 'DEFAULT', - RELATIVE2 = 'RELATIVE2', - ABSOLUTE1 = 'ABSOLUTE1', - ABSOLUTE2 = 'ABSOLUTE2', -} - -export class CreateProjectBody { - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - name: string; - - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - address: string; - - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - symbol: string; - - @IsOptional() - @IsString() - @ApiProperty({ type: 'string' }) - pointConsensus: string; - - @IsNotEmpty() - @IsNumber() - @Type(() => Number) - @ApiProperty({ type: 'number' }) - network: number; - - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - votePeriod: string; - - @ArrayNotEmpty() - @IsArray() - @ValidateNested({ each: true }) - @ApiProperty({ isArray: true }) - contributors: Contributor[]; - - @IsOptional() - @IsString() - @ApiProperty({ type: 'string', required: false }) - logo: string; - - @IsOptional() - @IsString() - @ApiProperty({ type: 'string', required: false }) - intro: string; - - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - @IsEnum(VoteSystemEnum) - voteSystem: VoteSystem; +import { ArrayNotEmpty, IsArray, IsNotEmpty, IsString } from 'class-validator'; +export class CreatePaymentBody extends AuthBody { @IsNotEmpty() @IsString() @ApiProperty({ type: 'string' }) - @IsEnum(VoteApproveEnum) - voteApprove: VoteApprove; + purpose: string; - @IsNotEmpty() - @IsNumber() - @Type(() => Number) - @ApiProperty({ type: 'number' }) - voteThreshold: number; -} - -export class UpdateProjectBody extends AuthBody { @IsNotEmpty() @IsString() @ApiProperty({ type: 'string' }) - name: string; + category: string; @IsNotEmpty() @IsString() @ApiProperty({ type: 'string' }) - votePeriod: string; + chainId: string; @IsNotEmpty() @IsString() @ApiProperty({ type: 'string' }) - logo: string; + allocate: string; @IsNotEmpty() @IsString() @ApiProperty({ type: 'string' }) - intro: string; + projectId: string; @IsNotEmpty() @IsString() @ApiProperty({ type: 'string' }) - @IsEnum(VoteSystem) - voteSystem: VoteSystem; + symbol: string; @IsNotEmpty() @IsString() @ApiProperty({ type: 'string' }) - @IsEnum(VoteApprove) - voteApprove: VoteApprove; - - @IsNotEmpty() - @IsNumber() - @Type(() => Number) - @ApiProperty({ type: 'number' }) - voteThreshold: number; + amount: string; - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - rule: string; + @ArrayNotEmpty() + @IsArray() + @ApiProperty({ isArray: true }) + counterparties: string[]; } export class PaymentListQuery extends PaginateQuery { @@ -145,29 +51,3 @@ export class PaymentListQuery extends PaginateQuery { @ApiProperty({ type: 'string' }) projectId: string; } - -export class CreateContributionTypeBody { - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - name: string; - - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - color: string; -} - -export class UpdateContributionTypeBody extends CreateContributionTypeBody { - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - id: string; -} - -export class DeleteContributionTypeBody { - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - id: string; -} From f2c0449e0be7ef41a31cc6b5e820bb8f5952404f Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 18:08:10 +0800 Subject: [PATCH 09/14] feat: update createPayment api --- .../migrations/20240220100436_payment3/migration.sql | 8 ++++++++ .../migrations/20240220100530_payment4/migration.sql | 10 ++++++++++ .../migrations/20240220100709_payment5/migration.sql | 10 ++++++++++ prisma/schema.prisma | 1 + src/core/service/payment.service.ts | 1 + 5 files changed, 30 insertions(+) create mode 100644 prisma/migrations/20240220100436_payment3/migration.sql create mode 100644 prisma/migrations/20240220100530_payment4/migration.sql create mode 100644 prisma/migrations/20240220100709_payment5/migration.sql diff --git a/prisma/migrations/20240220100436_payment3/migration.sql b/prisma/migrations/20240220100436_payment3/migration.sql new file mode 100644 index 0000000..185f367 --- /dev/null +++ b/prisma/migrations/20240220100436_payment3/migration.sql @@ -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; diff --git a/prisma/migrations/20240220100530_payment4/migration.sql b/prisma/migrations/20240220100530_payment4/migration.sql new file mode 100644 index 0000000..9e4acac --- /dev/null +++ b/prisma/migrations/20240220100530_payment4/migration.sql @@ -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; diff --git a/prisma/migrations/20240220100709_payment5/migration.sql b/prisma/migrations/20240220100709_payment5/migration.sql new file mode 100644 index 0000000..8db964d --- /dev/null +++ b/prisma/migrations/20240220100709_payment5/migration.sql @@ -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; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e933d34..eaccf54 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -133,6 +133,7 @@ model Payment { amount String project Project @relation(fields: [projectId], references: [id]) projectId String + creator String createAt DateTime @default(now()) updatedAt DateTime @updatedAt deleted Boolean @default(false) diff --git a/src/core/service/payment.service.ts b/src/core/service/payment.service.ts index 7e0b645..098fd13 100644 --- a/src/core/service/payment.service.ts +++ b/src/core/service/payment.service.ts @@ -51,6 +51,7 @@ export class PaymentService { return this.prisma.payment.create({ data: { ...data, + creator: wallet, projectId, }, }); From aee5da94567a2fdc1c357a0805e1ef77ff79848e Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 18:11:13 +0800 Subject: [PATCH 10/14] feat: payment moudle --- src/app.module.ts | 2 ++ src/controller/payment.controller.ts | 5 ++--- src/module/payment.module.ts | 9 +++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/module/payment.module.ts diff --git a/src/app.module.ts b/src/app.module.ts index 9a63abf..e51d158 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -3,6 +3,7 @@ import LogsMiddleware from '@/src/middleware/logs'; import { ContributionModule } from '@/src/module/contribution.module'; import { ContributorModule } from '@/src/module/contributor.module'; import { EasModule } from '@/src/module/eas.module'; +import { PaymentModule } from '@/src/module/payment.module'; import { UserModule } from '@/src/module/user.module'; import { Logger, MiddlewareConsumer, Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; @@ -31,6 +32,7 @@ import { ProjectModule } from './module/project.module'; UserModule, ContributionModule, EasModule, + PaymentModule, ], providers: [ { diff --git a/src/controller/payment.controller.ts b/src/controller/payment.controller.ts index ed4fbfa..7f6bd6e 100644 --- a/src/controller/payment.controller.ts +++ b/src/controller/payment.controller.ts @@ -2,12 +2,11 @@ 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'; -import { UserService } from '@service/user.service'; @Controller('payment') -export class UserController { +export class PaymentController { constructor( - @Inject(UserService) + @Inject(PaymentService) private readonly paymentService: PaymentService, ) {} diff --git a/src/module/payment.module.ts b/src/module/payment.module.ts new file mode 100644 index 0000000..7ca442f --- /dev/null +++ b/src/module/payment.module.ts @@ -0,0 +1,9 @@ +import { PaymentController } from '@controller/payment.controller'; +import { Module } from '@nestjs/common'; +import { PaymentService } from '@service/payment.service'; + +@Module({ + controllers: [PaymentController], + providers: [PaymentService], +}) +export class PaymentModule {} From 3e6ab2d063bc0ca710ea1c619b4346be444a3b0e Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 18:12:39 +0800 Subject: [PATCH 11/14] feat: update createPayment api --- prisma/migrations/20240220101214_payment6/migration.sql | 8 ++++++++ prisma/schema.prisma | 1 + src/core/type/doc/payment.ts | 5 +++++ 3 files changed, 14 insertions(+) create mode 100644 prisma/migrations/20240220101214_payment6/migration.sql diff --git a/prisma/migrations/20240220101214_payment6/migration.sql b/prisma/migrations/20240220101214_payment6/migration.sql new file mode 100644 index 0000000..b2d60cf --- /dev/null +++ b/prisma/migrations/20240220101214_payment6/migration.sql @@ -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; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index eaccf54..8cba4c0 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -134,6 +134,7 @@ model Payment { project Project @relation(fields: [projectId], references: [id]) projectId String creator String + txHash String createAt DateTime @default(now()) updatedAt DateTime @updatedAt deleted Boolean @default(false) diff --git a/src/core/type/doc/payment.ts b/src/core/type/doc/payment.ts index 6270799..bb5eac7 100644 --- a/src/core/type/doc/payment.ts +++ b/src/core/type/doc/payment.ts @@ -39,6 +39,11 @@ export class CreatePaymentBody extends AuthBody { @ApiProperty({ type: 'string' }) amount: string; + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + txHash: string; + @ArrayNotEmpty() @IsArray() @ApiProperty({ isArray: true }) From 364669c1fa355a74331b4fcf85012f2827484be7 Mon Sep 17 00:00:00 2001 From: KieSun Date: Tue, 20 Feb 2024 18:33:39 +0800 Subject: [PATCH 12/14] feat: filter record --- src/controller/contribution.controller.ts | 7 ++++ src/core/service/contribution.service.ts | 39 +++++++++++++++++++++++ src/core/type/doc/contribution.ts | 19 +++++++++++ 3 files changed, 65 insertions(+) diff --git a/src/controller/contribution.controller.ts b/src/controller/contribution.controller.ts index d7eec92..c4c387b 100644 --- a/src/controller/contribution.controller.ts +++ b/src/controller/contribution.controller.ts @@ -3,6 +3,7 @@ import { ContributionListQuery, CreateContributionBody, DeleteContributionBody, + GetAllocationDetailsQuery, PrepareClaimBody, UpdateContributionStateBody, } from '@core/type/doc/contribution'; @@ -64,4 +65,10 @@ export class ContributionController { await this.contributionService.deleteContribution(contributionId, body); return CoreApiResponse.success(); } + + @Get('allocationDetails') + async getAllocationDetails(@Query() query: GetAllocationDetailsQuery) { + const data = await this.contributionService.getAllocationDetails(query); + return CoreApiResponse.success(data); + } } diff --git a/src/core/service/contribution.service.ts b/src/core/service/contribution.service.ts index 657aac4..43a353c 100644 --- a/src/core/service/contribution.service.ts +++ b/src/core/service/contribution.service.ts @@ -3,6 +3,7 @@ import { ContributionListQuery, CreateContributionBody, DeleteContributionBody, + GetAllocationDetailsQuery, PrepareClaimBody, UpdateContributionStateBody, } from '@core/type/doc/contribution'; @@ -292,4 +293,42 @@ export class ContributionService { }, }); } + + async getAllocationDetails(query: GetAllocationDetailsQuery) { + const { endDate, startDate, projectId } = query; + 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 contributions = await this.prisma.contribution.findMany({ + where: { + projectId, + deleted: false, + status: Status.CLAIM, + startDate: { + gte: new Date(startDate), + }, + endDate: { + lte: new Date(endDate), + }, + }, + }); + const data: Record = {}; + contributions.forEach((item) => { + const contributorId = item.toIds[0]; + if (!data[contributorId]) { + data[contributorId] = 0; + } + data[contributorId] += item.credit; + }); + return data; + } } diff --git a/src/core/type/doc/contribution.ts b/src/core/type/doc/contribution.ts index e7554b9..44fa71e 100644 --- a/src/core/type/doc/contribution.ts +++ b/src/core/type/doc/contribution.ts @@ -102,3 +102,22 @@ export class PrepareClaimBody { } export class DeleteContributionBody extends AuthBody {} + +export class GetAllocationDetailsQuery { + @IsNotEmpty() + @IsString() + @ApiProperty({ type: 'string' }) + projectId: string; + + @IsNotEmpty() + @IsNumber() + @Type(() => Number) + @ApiProperty({ type: 'number' }) + startDate: number; + + @IsNotEmpty() + @IsNumber() + @Type(() => Number) + @ApiProperty({ type: 'number' }) + endDate: number; +} From 9a88829dac6c217b190632f7417b88e9f355ba07 Mon Sep 17 00:00:00 2001 From: KieSun Date: Sun, 25 Feb 2024 16:06:40 +0800 Subject: [PATCH 13/14] feat: UpdateProjectBody --- src/core/service/project.service.ts | 4 +--- src/core/type/doc/project.ts | 5 ----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/core/service/project.service.ts b/src/core/service/project.service.ts index 4e283cd..6962487 100644 --- a/src/core/service/project.service.ts +++ b/src/core/service/project.service.ts @@ -169,7 +169,6 @@ export class ProjectService { voteApprove, voteSystem, voteThreshold, - rule, operatorId, } = body; await this.getProject(projectId, true); @@ -178,7 +177,7 @@ export class ProjectService { id: operatorId, }, }); - if (user?.permission === Permission.Contributor) { + if (user?.permission !== Permission.Admin) { throw new HttpException(Code.NO_AUTH.message, Code.NO_AUTH.code); } this.checkVoteThreshold(voteThreshold); @@ -194,7 +193,6 @@ export class ProjectService { voteApprove, voteSystem, voteThreshold, - rule, }, }); } diff --git a/src/core/type/doc/project.ts b/src/core/type/doc/project.ts index a859205..a9843d6 100644 --- a/src/core/type/doc/project.ts +++ b/src/core/type/doc/project.ts @@ -132,11 +132,6 @@ export class UpdateProjectBody extends AuthBody { @Type(() => Number) @ApiProperty({ type: 'number' }) voteThreshold: number; - - @IsNotEmpty() - @IsString() - @ApiProperty({ type: 'string' }) - rule: string; } export class ProjectListQuery extends PaginateQuery { From 3f3709621ee26b6f19feebd3e413846f45b46da3 Mon Sep 17 00:00:00 2001 From: KieSun Date: Sun, 25 Feb 2024 16:09:25 +0800 Subject: [PATCH 14/14] feat: update getAllocationDetails api --- src/core/service/contribution.service.ts | 8 +++----- src/core/type/doc/contribution.ts | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/service/contribution.service.ts b/src/core/service/contribution.service.ts index 43a353c..65ef536 100644 --- a/src/core/service/contribution.service.ts +++ b/src/core/service/contribution.service.ts @@ -295,7 +295,7 @@ export class ContributionService { } async getAllocationDetails(query: GetAllocationDetailsQuery) { - const { endDate, startDate, projectId } = query; + const { endDateFrom, endDateTo, projectId } = query; const project = await this.prisma.project.findFirst({ where: { id: projectId, @@ -313,11 +313,9 @@ export class ContributionService { projectId, deleted: false, status: Status.CLAIM, - startDate: { - gte: new Date(startDate), - }, endDate: { - lte: new Date(endDate), + gte: new Date(endDateFrom), + lte: new Date(endDateTo), }, }, }); diff --git a/src/core/type/doc/contribution.ts b/src/core/type/doc/contribution.ts index 44fa71e..4bd4def 100644 --- a/src/core/type/doc/contribution.ts +++ b/src/core/type/doc/contribution.ts @@ -113,11 +113,11 @@ export class GetAllocationDetailsQuery { @IsNumber() @Type(() => Number) @ApiProperty({ type: 'number' }) - startDate: number; + endDateFrom: number; @IsNotEmpty() @IsNumber() @Type(() => Number) @ApiProperty({ type: 'number' }) - endDate: number; + endDateTo: number; }