Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lock assest with meshJs & json datum
- Loading branch information
1 parent
3fe1b71
commit bf55526
Showing
12 changed files
with
349 additions
and
60 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,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AdminWalletController } from './controller'; | ||
|
||
describe('AdminWalletController', () => { | ||
let controller: AdminWalletController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [AdminWalletController], | ||
}).compile(); | ||
|
||
controller = module.get<AdminWalletController>(AdminWalletController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).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,58 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Param, | ||
Post, | ||
Put, | ||
Response, | ||
Query, | ||
Request, | ||
} from '@nestjs/common'; | ||
import { CreateAdminWalletDto } from './dto/create.dto'; | ||
import { UpdateAdminWalletDto } from './dto/update.dto'; | ||
import { AdminWalletService } from './service'; | ||
import { queryTransform, formatRaList } from '../flatworks/utils/getlist'; | ||
import getToken from '../flatworks/utils/token'; | ||
|
||
import { JwtService } from '@nestjs/jwt'; | ||
import { userJwtPayload } from '../flatworks/types/types'; | ||
|
||
@Controller('adminwallets') | ||
export class AdminWalletController { | ||
constructor( | ||
private readonly service: AdminWalletService, | ||
private readonly jwtService: JwtService, | ||
) {} | ||
|
||
@Get() | ||
async index(@Response() res: any, @Query() query) { | ||
const mongooseQuery = queryTransform(query); | ||
const result = await this.service.findAll(mongooseQuery); | ||
return formatRaList(res, result); | ||
} | ||
|
||
@Get(':id') | ||
async find(@Param('id') id: string) { | ||
return await this.service.findOne(id); | ||
} | ||
|
||
@Post() | ||
async create(@Body() createAdminWalletDto: CreateAdminWalletDto) { | ||
return await this.service.create(createAdminWalletDto); | ||
} | ||
|
||
@Put(':id') | ||
async update( | ||
@Param('id') id: string, | ||
@Body() updateAdminWalletDto: UpdateAdminWalletDto, | ||
) { | ||
return await this.service.update(id, updateAdminWalletDto); | ||
} | ||
|
||
@Delete(':id') | ||
async delete(@Param('id') id: string) { | ||
return await this.service.delete(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,6 @@ | ||
export class BaseAdminWalletDto { | ||
address: string; | ||
pKeyHash: string; | ||
pKeyHashBech32: string; | ||
description: string; | ||
} |
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,4 @@ | ||
// Wallet/dto/create-Wallet.dto.ts | ||
import { BaseAdminWalletDto } from './base.dto'; | ||
|
||
export class CreateAdminWalletDto extends BaseAdminWalletDto {} |
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,6 @@ | ||
// todo/dto/update-todo.dto.ts | ||
import { BaseAdminWalletDto } from './base.dto'; | ||
|
||
export class UpdateAdminWalletDto extends BaseAdminWalletDto { | ||
completedAt: Date; | ||
} |
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,17 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AdminWalletService } from './service'; | ||
import { AdminWalletController } from './controller'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { AdminWallet, AdminWalletSchema } from './schemas/schema'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
|
||
@Module({ | ||
providers: [AdminWalletService, JwtService], | ||
controllers: [AdminWalletController], | ||
imports: [ | ||
MongooseModule.forFeature([ | ||
{ name: AdminWallet.name, schema: AdminWalletSchema }, | ||
]), | ||
], | ||
}) | ||
export class AdminWalletModule {} |
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 { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||
import { Document } from 'mongoose'; | ||
import * as uniqueValidator from 'mongoose-unique-validator'; | ||
|
||
export type AdminWalletDocument = AdminWallet & Document; | ||
|
||
@Schema() | ||
export class AdminWallet { | ||
@Prop({ required: true, unique: true }) | ||
address: string; | ||
|
||
@Prop() | ||
pKeyHash?: string; | ||
|
||
@Prop() | ||
pKeyHashBech32?: string; | ||
|
||
@Prop() | ||
completedAt?: Date; | ||
|
||
@Prop() | ||
createdAt?: Date; | ||
} | ||
|
||
const AdminWalletSchema = SchemaFactory.createForClass(AdminWallet); | ||
AdminWalletSchema.plugin(uniqueValidator); | ||
|
||
export { AdminWalletSchema }; |
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 { AdminWalletService } from './service'; | ||
|
||
describe('AdminWalletService', () => { | ||
let service: AdminWalletService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [AdminWalletService], | ||
}).compile(); | ||
|
||
service = module.get<AdminWalletService>(AdminWalletService); | ||
}); | ||
|
||
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,62 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Model } from 'mongoose'; | ||
import { CreateAdminWalletDto } from './dto/create.dto'; | ||
import { UpdateAdminWalletDto } from './dto/update.dto'; | ||
import { AdminWallet, AdminWalletDocument } from './schemas/schema'; | ||
import { RaList, MongooseQuery } from '../flatworks/types/types'; | ||
import { inspectAddress } from 'cardano-addresses'; | ||
|
||
@Injectable() | ||
export class AdminWalletService { | ||
constructor( | ||
@InjectModel(AdminWallet.name) | ||
private readonly model: Model<AdminWalletDocument>, | ||
) {} | ||
|
||
async findAll(query: MongooseQuery): Promise<RaList> { | ||
const count = await this.model.find(query.filter).count().exec(); | ||
const data = await this.model | ||
.find(query.filter) | ||
.sort(query.sort) | ||
.skip(query.skip) | ||
.limit(query.limit) | ||
.exec(); | ||
|
||
return { count: count, data: data }; | ||
} | ||
|
||
async findOne(id: string): Promise<AdminWallet> { | ||
return await this.model.findById(id).exec(); | ||
} | ||
|
||
async findByUser(userId: string): Promise<AdminWallet> { | ||
return await this.model.findOne({ userId }).exec(); | ||
} | ||
|
||
async create( | ||
createAdminWalletDto: CreateAdminWalletDto, | ||
): Promise<AdminWallet> { | ||
const address = createAdminWalletDto.address; | ||
console.log(address); | ||
|
||
const info = (await inspectAddress(address)) as any; | ||
return await new this.model({ | ||
...createAdminWalletDto, | ||
createdAt: new Date(), | ||
pKeyHash: info.spending_key_hash, | ||
pKeyHashBech32: info.spending_key_hash_bech32, | ||
}).save(); | ||
} | ||
|
||
async update( | ||
id: string, | ||
updateAdminWalletDto: UpdateAdminWalletDto, | ||
): Promise<AdminWallet> { | ||
return await this.model.findByIdAndUpdate(id, updateAdminWalletDto).exec(); | ||
} | ||
|
||
async delete(id: string): Promise<AdminWallet> { | ||
return await this.model.findByIdAndDelete(id).exec(); | ||
} | ||
} |
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.