Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get single drop endpoint implementation #32

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/database/migrations/1651143902595-create_nfts_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ export class createNftsTable1651143902595 implements MigrationInterface {
"ownerId" int8,
"creatorAddress" varchar NOT NULL,
"creatorId" int8,
"creatorUsername" varchar,
"ownerUsername" varchar,
"name" varchar NOT NULL,
"description" varchar NOT NULL,
"fileSize" float4 DEFAULT 0.0,
"fileType" varchar,
"listed" bool DEFAULT false,
"listedOnchain" bool DEFAULT false,
"listedOnChain" bool DEFAULT false,
"verified" bool DEFAULT false,
"isVideo" bool DEFAULT false,
"image" varchar,
Expand Down
10 changes: 9 additions & 1 deletion src/modules/nfts-drops/nfts-drops.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Post, Body } from '@nestjs/common';
import { Controller, Post, Body, Get, Param } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { NftsDropsService } from './nfts-drops.service';
import { NftsService } from '../nfts/nfts.service';
Expand All @@ -9,6 +9,14 @@ import { CreateDropDto } from './nfts-drops.dto';
export class NftsDropsController {
constructor(private readonly dropService: NftsDropsService, private readonly nftService: NftsService) {}

@Get('/:dropID')
async findOneByDropId(@Param('dropID') dropID: string) {
const drop = await this.dropService.findOneByDropID(dropID);
return {
drop,
};
}

@Post('/')
async createDrop(@Body() dropData: CreateDropDto) {
const drop = await this.dropService.save(dropData);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/nfts-drops/nfts-drops.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class NftsDropsService {

findOneByDropID(dropID: string): Promise<NftDrop> {
return this.dropRepository.findOne({
relations: ['creator'],
relations: ['creator', 'nfts'],
where: { dropID },
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/modules/nfts/nfts.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ export class Nft {
@JoinColumn()
owner: User;

@Column({ nullable: true, type: 'int8', default: null })
dropId: number;

@ManyToOne(() => NftDrop, (drop: NftDrop) => drop.nfts)
@JoinColumn()
drop: NftDrop;
Expand Down
13 changes: 10 additions & 3 deletions src/modules/users/users.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Controller, Get, Param, Put, Body, BadRequestException, CacheTTL, UseGuards } from '@nestjs/common';

import { ApiTags } from '@nestjs/swagger';
import { WalletSignatureGuard } from 'src/guards/walletSignature.guard';
import { isValidAddress } from 'src/utils/Utils';
import { NftsService } from '../nfts/nfts.service';
import { UsersService } from './users.service';
import { UserUpdateProfileDto } from './users.dto';
import { Web3Helper } from '../../utils/web3Helper';
import { WalletSignatureGuard } from '../../guards/walletSignature.guard';

@ApiTags('users')
@Controller('users')
@UseGuards(WalletSignatureGuard)
export class UsersController {
constructor(private readonly userService: UsersService, private readonly nftService: NftsService) {}

Expand All @@ -17,6 +18,12 @@ export class UsersController {
async updateProfile(@Body() userData: UserUpdateProfileDto) {
const checksumAddress = Web3Helper.getAddressChecksum(userData.walletAddress);

const foundUser = await this.userService.findByAddress(checksumAddress);

if (userData.username && foundUser?.username?.toLocaleLowerCase() !== userData?.username?.toLocaleLowerCase()) {
const newFoundUser = await this.userService.findByUsername(userData.username);


const foundUser = await this.userService.findByAddress(checksumAddress);

if (userData.username && foundUser?.username?.toLocaleLowerCase() !== userData?.username?.toLocaleLowerCase()) {
Expand Down Expand Up @@ -84,4 +91,4 @@ export class UsersController {
user,
};
}
}
}
21 changes: 4 additions & 17 deletions src/modules/users/users.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { IsString, IsOptional } from 'class-validator';
import { IsString, IsOptional, IsNumber } from 'class-validator';

export class UserDto {
readonly walletAddress: string;
}

export class UserUpdateProfileDto {
@IsNumber()
readonly id: number;

@IsString()
readonly walletAddress: string;

Expand Down Expand Up @@ -36,22 +39,6 @@ export class UserUpdateProfileDto {
@IsOptional()
readonly coverThumbnailUrl?: string;

@IsString()
@IsOptional()
readonly socialUrl?: string;

@IsString()
@IsOptional()
readonly twitterUrl?: string;

@IsString()
@IsOptional()
readonly instagramUrl?: string;

@IsString()
@IsOptional()
readonly facebookUrl?: string;

@IsString()
signature?: string;
}