src/module-manager/module-manager.controller.ts
/api/v1/module
Methods |
|
| Async create | ||||||
create(createModuleManagerDto: CreateModuleManagerDto)
|
||||||
Decorators :
@UseGuards(new RolesAuthGuard())
|
||||||
|
Parameters :
Returns :
unknown
|
| Async deleteLibreModule | |||||||||
deleteLibreModule(request: AuthRequest, registerModule: ModuleDto)
|
|||||||||
Decorators :
@UseGuards(new RolesAuthGuard())
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async findAll | ||||||
findAll(filterModuleManagerDto: FilterModuleManagerDto)
|
||||||
Decorators :
@Get('/')
|
||||||
|
Parameters :
Returns :
unknown
|
| Async findOne | ||||||
findOne(id: string)
|
||||||
Decorators :
@Get('/:id')
|
||||||
|
Parameters :
Returns :
unknown
|
| getTransactionInput | |||||||||
getTransactionInput(contractName: ContractName, txName: TransactionNames)
|
|||||||||
Decorators :
@Get('/:contractName/:txName')
|
|||||||||
|
Parameters :
Returns :
any
|
| Async registerLibreModule | |||||||||
registerLibreModule(request: AuthRequest, registerModule: ModuleDto)
|
|||||||||
Decorators :
@UseGuards(new RolesAuthGuard())
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async updateLibreModule | |||||||||
updateLibreModule(request: AuthRequest, updateModuleDto: UpdateModuleDto)
|
|||||||||
Decorators :
@UseGuards(new RolesAuthGuard())
|
|||||||||
|
Parameters :
Returns :
unknown
|
import {
BadRequestException,
Request,
Body,
Controller,
Delete,
Get,
InternalServerErrorException,
Param,
Post,
Put,
Query,
ServiceUnavailableException,
UseGuards,
} from "@nestjs/common";
import { RolesAuthGuard } from "src/auth/guards/roles-auth.guard";
import { CreateModuleManagerDto } from "./dto/create-ModuleManager.dto";
import { FilterModuleManagerDto } from "./dto/filter-ModuleManager.dto";
import { ModuleManagerService } from "./module-manager.service";
import {
AuthRequest,
ContractName,
TransactionNames,
} from "src/common/interfaces";
import {
getContractByName,
getRoleAndContractAddressByNameOrAddress,
} from "src/common/provider/web3/web3Provider";
import { ModuleDto } from "./dto/module.dto";
import { transactionSubmitter } from "src/common/provider";
import { UpdateModuleDto } from "./dto/update-module.dto";
import { AdminProfileService } from "src/admin-profile/admin-profile.service";
import { UserService } from "src/user/user.service";
@Controller("/api/v1/module")
export class ModuleManagerController {
constructor(
private readonly moduleManagerService: ModuleManagerService,
private readonly adminProfileService: AdminProfileService,
private readonly userService: UserService,
) {}
@UseGuards(new RolesAuthGuard(["admin", "fundAdmin"]))
@Post("/")
async create(@Body() createModuleManagerDto: CreateModuleManagerDto) {
try {
return await this.moduleManagerService.create(createModuleManagerDto);
} catch (error) {
console.error(error);
throw new InternalServerErrorException(error);
}
}
@UseGuards(new RolesAuthGuard(["admin", "fundAdmin"]))
@Post("dealer/rules-engine/register")
async registerLibreModule(
@Request() request: AuthRequest,
@Body() registerModule: ModuleDto,
) {
try {
const { user } = request;
const [{ contractAddress, role }, signerKey] = await Promise.all([
getRoleAndContractAddressByNameOrAddress({
userAddress: process.env.ADMIN_WALLET_ADDRESS,
contractName: ContractName.DealerRulesEngine,
transactionName: TransactionNames.registerLibreModule,
}),
user.role === "admin"
? (
await this.adminProfileService.getCustodial(user.email)
).privateKey
: (
await this.userService.getCustodial(user.email)
).privateKey,
]);
return await transactionSubmitter({
signerKey,
contractName: ContractName.DealerRulesEngine,
contractAddress,
transactionName: TransactionNames.registerLibreModule,
args: [registerModule.contractAddress, role],
});
} catch (error) {
console.error(error);
throw new ServiceUnavailableException(error);
}
}
@UseGuards(new RolesAuthGuard(["admin", "fundAdmin"]))
@Put("dealer/rules-engine/update")
async updateLibreModule(
@Request() request: AuthRequest,
@Body() updateModuleDto: UpdateModuleDto,
) {
try {
const { user } = request;
const [{ contractAddress, role }, signerKey] = await Promise.all([
getRoleAndContractAddressByNameOrAddress({
userAddress: process.env.ADMIN_WALLET_ADDRESS,
contractName: ContractName.DealerRulesEngine,
transactionName: TransactionNames.registerLibreModule,
}),
user.role === "admin"
? (
await this.adminProfileService.getCustodial(user.email)
).privateKey
: (
await this.userService.getCustodial(user.email)
).privateKey,
]);
return await transactionSubmitter({
signerKey,
contractName: ContractName.DealerRulesEngine,
contractAddress,
transactionName: TransactionNames.editLibreModule,
args: [
updateModuleDto.contractAddress,
updateModuleDto.status,
role,
updateModuleDto.moduleRegistrationTimestamp,
], // 1697615739 the number of the current uploaded module until we add events on SM
});
} catch (error) {
console.error(error);
throw new ServiceUnavailableException(error);
}
}
@UseGuards(new RolesAuthGuard(["admin", "fundAdmin"]))
@Delete("dealer/rules-engine/delete")
async deleteLibreModule(
@Request() request: AuthRequest,
@Body() registerModule: ModuleDto,
) {
const { user } = request;
const [{ contractAddress, role }, signerKey] = await Promise.all([
getRoleAndContractAddressByNameOrAddress({
userAddress: process.env.ADMIN_WALLET_ADDRESS,
contractName: ContractName.DealerRulesEngine,
transactionName: TransactionNames.registerLibreModule,
}),
user.role === "admin"
? (
await this.adminProfileService.getCustodial(user.email)
).privateKey
: (
await this.userService.getCustodial(user.email)
).privateKey,
]);
return await transactionSubmitter({
signerKey,
contractName: ContractName.DealerRulesEngine,
contractAddress,
transactionName: TransactionNames.deleteLibreModule,
args: [registerModule.contractAddress, role],
});
}
@Get("/")
async findAll(@Query() filterModuleManagerDto: FilterModuleManagerDto) {
try {
if (Object.keys(filterModuleManagerDto).length) {
return await this.moduleManagerService.findByFilter(
filterModuleManagerDto,
);
}
return await this.moduleManagerService.findAll();
} catch (error) {
console.error(error);
throw new InternalServerErrorException(error);
}
}
@Get("/:id")
async findOne(@Param("id") id: string) {
try {
return await this.moduleManagerService.findOne(id);
} catch (error) {
console.error(error);
throw new InternalServerErrorException(error);
}
}
@Get("/:contractName/:txName")
getTransactionInput(
@Param("contractName") contractName: ContractName,
@Param("txName") txName: TransactionNames,
) {
try {
const txAbi = getContractByName[contractName].abis.find((tx) => {
return txName === tx.name;
});
return this.moduleManagerService.getDynamicInput([txAbi]);
} catch (error) {
console.error(error);
throw new BadRequestException(error);
}
}
}