-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user accounts and connect it to the token accounts
- Loading branch information
1 parent
040c8ef
commit f30f366
Showing
8 changed files
with
148 additions
and
23 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
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,25 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import {IsString} from 'class-validator'; | ||
import {Transform, Type} from "class-transformer"; | ||
|
||
export class AddUserDto { | ||
@ApiProperty({ type: String, required: true }) | ||
@Transform((address) => address.value.trim().toLowerCase()) | ||
@Type(() => String) | ||
@IsString() | ||
address: string; | ||
} | ||
|
||
export class GetUsersDto { | ||
@ApiProperty({ type: Number, required: false, default: '100' }) | ||
// @Transform((limit) => limit.value.toNumber()) | ||
@Type(() => String) | ||
@IsString() | ||
limit: number; | ||
|
||
@ApiProperty({ type: Number, required: false, default: '0' }) | ||
// @Transform((offset) => offset.value.toNumber()) | ||
@Type(() => String) | ||
@IsString() | ||
offset: number; | ||
} |
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,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserService } from './user.service'; | ||
|
||
describe('UserService', () => { | ||
let service: UserService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [UserService], | ||
}).compile(); | ||
|
||
service = module.get<UserService>(UserService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
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,28 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import {DataSource} from "typeorm"; | ||
import {Token, UserAccount} from "../entities"; | ||
import {AddUserDto, GetUsersDto} from "../dto/user.dto"; | ||
|
||
@Injectable() | ||
export class UserService { | ||
constructor(private dataSource: DataSource,) { | ||
} | ||
|
||
async addNewUser(dto: AddUserDto) { | ||
const { address } = dto | ||
|
||
const data = await this.dataSource.manager.insert(UserAccount, { | ||
address: address.toLowerCase(), | ||
username: address.replaceAll('0x', '').slice(0, 6) | ||
}) | ||
return data.identifiers[0].id | ||
} | ||
|
||
async getUserByAddress(address: string) { | ||
return await this.dataSource.manager.findOne(UserAccount, { | ||
where: { | ||
address: address.toLowerCase(), | ||
}, | ||
}) | ||
} | ||
} |