Skip to content

Commit

Permalink
Merge pull request #25 from aura-nw/fix-get-list-launchpad
Browse files Browse the repository at this point in the history
update query collection
  • Loading branch information
ThienLK1 authored Aug 6, 2024
2 parents c105289 + 0627a7b commit 624a623
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."launchpad" add column "relate_key_words" jsonb
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."launchpad" add column "relate_key_words" jsonb
null;
3 changes: 3 additions & 0 deletions src/modules/collection/dto/list-launchpad-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ export class ListLaunchpadRequestDtoParam {

@ApiPropertyOptional({ type: [String], example: '' })
status: string[];

@ApiPropertyOptional({ example: '' })
keyword: string;
}
34 changes: 17 additions & 17 deletions src/modules/collection/launchpad.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import { CreateLaunchpadRequestDto } from './dto/create-launchpad-request.dto';
import { PublishLaunchpadRequestDtoParam } from './dto/publish-launchpad-request.dto';
import { UnPublishLaunchpadRequestDtoParam } from './dto/unpublish-launchpad-request.dto';
import { DetailLaunchpadLanguageRequestDtoParam } from './dto/detail-launchpad-language-request.dto';
import {
EditDraftLaunchpadRequestDto,
} from './dto/edit-draft-launchpad-request.dto';
import { EditDraftLaunchpadRequestDto } from './dto/edit-draft-launchpad-request.dto';
import { ListLaunchpadRequestDtoParam } from './dto/list-launchpad-request.dto';
import { MintRequestDtoParam } from './dto/mint-nft-request.dto';
import { DetailLaunchpadBySlugRequestDtoParam, DetailLaunchpadRequestDtoParam } from './dto/detail-launchpad-request.dto';
import {
DetailLaunchpadBySlugRequestDtoParam,
DetailLaunchpadRequestDtoParam,
} from './dto/detail-launchpad-request.dto';

@Controller('launchpad')
@ApiTags('launchpad')
Expand All @@ -42,7 +43,6 @@ export class LaunchpadController {
@Post()
@ApiConsumes('multipart/form-data')
@UseInterceptors(AuthUserInterceptor, AnyFilesInterceptor())
// @UseInterceptors( AnyFilesInterceptor())
create(
@Body() data: CreateLaunchpadRequestDto,
@UploadedFiles() files: Array<Express.Multer.File>
Expand Down Expand Up @@ -87,28 +87,28 @@ export class LaunchpadController {
@Get('id/:launchpad_id')
@UseInterceptors(AuthUserInterceptor)
detailLaunchpadDetail(@Param() param: DetailLaunchpadRequestDtoParam) {
return this.launchpadSvc.launchpadDetail(
param.launchpad_id,
);
return this.launchpadSvc.launchpadDetail(param.launchpad_id);
}

// @UseGuards(AuthGuard, RolesGuard)
// @ApiBearerAuth()
// @Roles(Role.Admin, Role.User)
@Get('slug/:launchpad_slug')
@UseInterceptors(AuthUserInterceptor)
detailLaunchpadDetailBySlug(@Param() param: DetailLaunchpadBySlugRequestDtoParam) {
return this.launchpadSvc.launchpadDetailBySlug(
param.launchpad_slug,
);
detailLaunchpadDetailBySlug(
@Param() param: DetailLaunchpadBySlugRequestDtoParam
) {
return this.launchpadSvc.launchpadDetailBySlug(param.launchpad_slug);
}

// @UseGuards(AuthGuard, RolesGuard)
// @ApiBearerAuth()
// @Roles(Role.Admin, Role.User)
@Get(':launchpad_id/:language_id')
@UseInterceptors(AuthUserInterceptor)
detailLaunchpadLanguageDetail(@Param() param: DetailLaunchpadLanguageRequestDtoParam) {
detailLaunchpadLanguageDetail(
@Param() param: DetailLaunchpadLanguageRequestDtoParam
) {
return this.launchpadSvc.launchpadLanguageDetail(
param.launchpad_id,
param.language_id
Expand All @@ -120,11 +120,12 @@ export class LaunchpadController {
// @Roles(Role.Admin, Role.User)
@Get('')
@UseInterceptors(AuthUserInterceptor)
listLaunchpadDetail(@Query() params: ListLaunchpadRequestDtoParam) {
listLaunchpad(@Query() params: ListLaunchpadRequestDtoParam) {
return this.launchpadSvc.getListLaunchpad(
params.limit,
params.offset,
params.status
params.status,
params.keyword
);
}

Expand All @@ -136,5 +137,4 @@ export class LaunchpadController {
mint(@Param() param: MintRequestDtoParam) {
return this.launchpadSvc.mintNFT(param.launchpad_id, param.nft_amount);
}

}
7 changes: 4 additions & 3 deletions src/modules/collection/launchpad.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export class LaunchpadGraphql {
return this.graphqlSvc.query(
this.configSvc.get<string>('graphql.endpoint'),
'',
`query launchpad($offset: Int = 0, $limit: Int = 10, $status: [String] = ["DRAFT", "PUBLISHED", "READY_TO_MINT"]) {
launchpad(offset: $offset, limit: $limit, order_by: {updated_at: desc}, where: {status: {_in: $status}}) {
`query launchpad($offset: Int = 0, $limit: Int = 10, $status: [String] = ["DRAFT", "PUBLISHED", "READY_TO_MINT"], $keyword: String = "%%") {
launchpad(offset: $offset, limit: $limit, order_by: {updated_at: desc}, where: {status: {_in: $status}, relate_key_words: {_cast: {String: {_ilike: $keyword}}}}) {
featured_images
id
launchpad_creator {
Expand All @@ -211,11 +211,12 @@ export class LaunchpadGraphql {
language_id
}
slug
created_at
updated_at
contract_address
creator_id
}
launchpad_aggregate(where: {status: {_in: $status}}) {
launchpad_aggregate(where: {status: {_in: $status}, relate_key_words: {_cast: {String: {_ilike: $keyword}}}}) {
aggregate {
count(columns: id)
}
Expand Down
18 changes: 12 additions & 6 deletions src/modules/collection/launchpad.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ export class LaunchpadService {
contract_address,
} = data;
const slug = generateSlug(name);
const relate_key_words = [name, name_in_vn];
// insert db
const result = await this.launchpadGraphql.insert({
data: {
creator_id,
status: LaunchpadStatus.Draft,
fund,
contract_address,
slug
slug,
relate_key_words,
},
});

Expand Down Expand Up @@ -237,7 +239,8 @@ export class LaunchpadService {
async getListLaunchpad(
limit: number,
offset: number,
status?: string[]
status?: string[],
keyword?: string
) {
// const { token } = ContextProvider.getAuthUser();
const variables: any = {
Expand All @@ -247,6 +250,9 @@ export class LaunchpadService {
if (status && status.length > 0) {
variables.status = status;
}
if (keyword) {
variables.keyword = `%${keyword}%`;
}

return this.launchpadGraphql.getListLaunchpad(
variables
Expand All @@ -256,7 +262,7 @@ export class LaunchpadService {

/**
* Admin can edit all field
* @param
* @param
*/
async editDraftLaunchpad(
data: EditDraftLaunchpadRequestDto,
Expand All @@ -279,7 +285,7 @@ export class LaunchpadService {
} = data;

const launchpad = await this.getExistingLaunchpad(launchpad_id);
if(launchpad.status != LaunchpadStatus.Draft){
if (launchpad.status != LaunchpadStatus.Draft) {
throw new BadRequestException('Launchpad status must be Draft');
}

Expand Down Expand Up @@ -385,11 +391,11 @@ export class LaunchpadService {

const { userId } = ContextProvider.getAuthUser();
const launchpad = await this.getExistingLaunchpad(launchpadId);
if(launchpad.status != LaunchpadStatus.Published){
if (launchpad.status != LaunchpadStatus.Published) {
throw new BadRequestException('Launchpad status must be Published!');
}
const userWallet = await this.userWalletService.deserialize(userId);
if(!userWallet){
if (!userWallet) {
throw new BadRequestException('Can not get user wallet!');
}
const launchpadContract = await this.userWalletService.getLaunchpadContract(
Expand Down

0 comments on commit 624a623

Please sign in to comment.