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

Erc1155 #3

Open
wants to merge 14 commits into
base: main
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
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": "airbnb-base",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
}
8 changes: 5 additions & 3 deletions api/services/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ let constants = require("../../config/constants");
class AdminService {
async createAdmin(params) {
try {
let { username, password } = params;
let admin = await prisma.admins.create({
data: {
username: params.username,
password: params.password,
username: username,
password: password,
},
});
return admin;
Expand All @@ -24,9 +25,10 @@ class AdminService {

async getAdmin(params) {
try {
let { username } = params;
let admin = await prisma.admins.findOne({
where: {
username: params.username,
username: username,
},
});
return admin;
Expand Down
37 changes: 20 additions & 17 deletions api/services/asset-migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ let categoryServiceInstance = new categoryService();
class AssetMigrateService {
async createAssetMigrate(params) {
try {
let { category_id, token_array, type, txhash, userId, block_number } = params;
let category = await categoryServiceInstance.getCategory({
categoryId: params.category_id,
categoryId: category_id,
});

console.log(category);
Expand All @@ -23,27 +24,27 @@ class AssetMigrateService {
if (params.type === "DEPOSIT") {
message =
"You initiated a deposit of " +
params.token_array.length +
token_array.length +
" " +
category.name +
" tokens";
}
if (params.type === "WITHDRAW") {
message =
"You initiated a withdraw of " +
params.token_array.length +
token_array.length +
" " +
category.name +
" tokens";
}
let assetMigrate = await prisma.assetmigrate.create({
data: {
type: params.type,
txhash: params.txhash,
categories: { connect: { id: parseInt(params.category_id) } },
users: { connect: { id: parseInt(params.userId) } },
token_array: { set: params.token_array },
block_number: params.block_number,
type: type,
txhash: txhash,
categories: { connect: { id: parseInt(category_id) } },
users: { connect: { id: parseInt(userId) } },
token_array: { set: token_array },
block_number: block_number,
message,
},
});
Expand Down Expand Up @@ -86,8 +87,9 @@ class AssetMigrateService {

async getAssetMigration(params) {
try {
let { assetMigrationId } = params;
let assetMigration = await prisma.assetmigrate.findOne({
where: { id: parseInt(params.assetMigrationId) },
where: { id: parseInt(assetMigrationId) },
});
return assetMigration;
} catch (err) {
Expand All @@ -99,29 +101,30 @@ class AssetMigrateService {
async updateAssetMigration(params) {
try {
let current = await this.getAssetMigration(params);

let { assetMigrationId: params_assetMigrationId, status: params_status, exit_txhash: params_exit_txhash } = params;
let { categories_id: current_categories_id, token_array: current_token_array, status: current_status, exit_txhash: current_exit_txhash } = current;
let category = await categoryServiceInstance.getCategory({
categoryId: current.categories_id,
categoryId: current_categories_id,
});

let message;

if (current.type === "WITHDRAW") {
message =
"You finished a withdraw of " +
current.token_array.length +
current_token_array.length +
" " +
category.name +
" tokens";
}
let assetMigration = await prisma.assetmigrate.update({
where: { id: parseInt(params.assetMigrationId) },
where: { id: parseInt(params_assetMigrationId) },
data: {
message,
status: params.status ? parseInt(params.status) : current.status,
status: params_status ? parseInt(params_status) : current_status,
exit_txhash: params.exit_txhash
? params.exit_txhash
: current.exit_txhash,
? params_exit_txhash
: current_exit_txhash,
},
});
return assetMigration;
Expand Down
37 changes: 22 additions & 15 deletions api/services/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ let constants = require("../../config/constants");

class CategoryService {
async createCategory(params, file) {
let { name, description, url, address, type, tokenURI } = params;
try {
let category = await prisma.categories.create({
data: {
name: params.name,
description: params.description,
url: params.url,
name: name,
description: description,
url: url,
img_url: file ? file.path : "",
categoriesaddresses: {
create: JSON.parse(params.address),
create: JSON.parse(address),
},
type: params.type,
tokenURI: params.tokenURI,
type: type,
tokenURI: tokenURI,
name_lowercase: name.toLowerCase()
},
});
return category;
Expand Down Expand Up @@ -77,8 +79,9 @@ class CategoryService {

async categoryExists(params) {
try {
let { name } = params;
let categories = await prisma.categories.findOne({
where: { name: params.name },
where: { name_lowercase: name.toLowerCase() },
});
return categories;
} catch (err) {
Expand All @@ -88,6 +91,7 @@ class CategoryService {
}

async categoryAddressExists(params) {
let { address } = params;
try {
let categories = await prisma.categoriesaddresses.findOne({
where: {
Expand All @@ -108,8 +112,9 @@ class CategoryService {

async getCategory(params) {
try {
let { categoryId } = params;
let categories = await prisma.categories.findOne({
where: { id: parseInt(params.categoryId) },
where: { id: parseInt(categoryId) },
});
return categories;
} catch (err) {
Expand All @@ -121,18 +126,20 @@ class CategoryService {
async updateCategory(params, file) {
try {
let current = await this.getCategory(params);
let { description: current_description, url: current_url, img_url: current_img_url, type: current_type } = current;
let { description: params_description, address: params_address, type: params_type, url: params_url } = params;
let category = await prisma.categories.update({
where: { id: parseInt(params.categoryId) },
data: {
description: params.description
? params.description
: current.description,
url: params.url ? params.url : current.url,
img_url: file ? file.path : current.img_url,
description: params_description
? params_description
: current_description,
url: params_url ? params_url : current_url,
img_url: file ? file.path : current_img_url,
categoriesaddresses: {
create: params.address ? JSON.parse(params.address) : [],
create: params_address ? JSON.parse(params_address) : [],
},
type: params.type ? params.type : current.type,
type: params_type ? params_type : current_type,
},
});
return category;
Expand Down
31 changes: 18 additions & 13 deletions api/services/erc20-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ let constants = require("../../config/constants");

class ERC20TokenService {
async addERC20Token(params) {
let { name, decimal, symbol, address } = params;
try {
let erc20Token = await prisma.erc20tokens.create({
data: {
name: params.name,
decimal: parseInt(params.decimal),
symbol: params.symbol,
name: name,
decimal: parseInt(decimal),
symbol: symbol,
erc20tokensaddresses: {
create: JSON.parse(params.address),
create: JSON.parse(address),
},
},
});
Expand Down Expand Up @@ -71,8 +72,9 @@ class ERC20TokenService {

async erc20TokenExists(params) {
try {
let { symbol } = params;
let erc20Tokens = await prisma.erc20tokens.findOne({
where: { symbol: params.symbol },
where: { symbol: symbol },
});
return erc20Tokens;
} catch (err) {
Expand All @@ -83,8 +85,9 @@ class ERC20TokenService {

async erc20TokenAddressExists(params) {
try {
let { address } = params;
let erc20Tokens = await prisma.erc20tokensaddresses.findOne({
where: { address: params.address },
where: { address: address },
});
return erc20Tokens;
} catch (err) {
Expand All @@ -95,8 +98,9 @@ class ERC20TokenService {

async getERC20Token(params) {
try {
let { id } = params;
let erc20Tokens = await prisma.erc20tokens.findOne({
where: { id: parseInt(params.id) },
where: { id: parseInt(id) },
include: { erc20tokensaddresses: true },
});
return erc20Tokens;
Expand All @@ -109,15 +113,16 @@ class ERC20TokenService {
async updateERC20Token(params) {
try {
let current = await this.getERC20Token(params);

let { name: params_name, decimal: params_decimal, market_price: params_market_price } = params
let { decimal: current_decimal, market_price: current_market_price, name: current_name } = current
let category = await prisma.erc20tokens.update({
where: { id: parseInt(params.id) },
data: {
name: params.name ? params.name : current.name,
decimal: params.decimal ? parseInt(params.decimal) : current.decimal,
market_price: params.market_price
? (params.market_price)
: current.market_price,
name: params_name ? params.name : current_name,
decimal: params_decimal ? parseInt(params_decimal) : current_decimal,
market_price: params_market_price
? (params_market_price)
: current_market_price,
},
});
return category;
Expand Down
Loading