Skip to content

Commit

Permalink
added get all networks API
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdulAhadArain committed May 10, 2023
1 parent 1dfae86 commit d2c6ed8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
13 changes: 13 additions & 0 deletions src/controllers/network.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ export const createNetwork = async (
}
};

export const getAllNetworks = async (
req: Request,
res: Response,
next: NextFunction,
): Promise<void> => {
try {
const networks = await networkService.getAllNetworks(req.params.id as any);
res.send(networks);
} catch (error) {
next(error);
}
};

export const getNetwork = async (
req: Request,
res: Response,
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/QuantumPortalAccount.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbiItem } from './index';
import { AbiItem } from 'web3-utils';

export interface QuantumPortalAccountBalance {
tokenId: string;
Expand Down
3 changes: 2 additions & 1 deletion src/routes/network.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ router
.post(
validate(networkValidation.createNetwork),
networkController.createNetwork,
);
)
.get(networkController.getAllNetworks);

router
.route('/:id')
Expand Down
43 changes: 16 additions & 27 deletions src/services/network.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,32 @@ const getNetworkById = async (id: ObjectId) => {
};

export const createNetwork = async (network: any): Promise<any> => {
try {
const setNetwork = await QuantumPortalNetworkModel.insertMany(network);
return setNetwork;
} catch (error) {
console.error(error);
}
const setNetwork = await QuantumPortalNetworkModel.insertMany(network);
return setNetwork;
};

export const getAllNetworks = async (id: ObjectId): Promise<INetwork[]> => {
const networks = await QuantumPortalNetworkModel.find();
return networks;
};

export const getNetwork = async (id: ObjectId): Promise<INetwork> => {
try {
const getNetwork = await QuantumPortalNetworkModel.findById(id);
return getNetwork;
} catch (error) {
console.error(error);
}
const network = await QuantumPortalNetworkModel.findById(id);
return network;
};

export const deleteNetwork = async (networkId: ObjectId): Promise<INetwork> => {
try {
const network = await getNetworkById(networkId);
await (network as any).deleteOne();
return network;
} catch (error) {
console.error(error);
}
const network = await getNetworkById(networkId);
await (network as any).deleteOne();
return network;
};

export const updateNetwork = async (
networkId: ObjectId,
updateBody: any,
): Promise<INetwork> => {
try {
const network = await getNetworkById(networkId);
Object.assign(network, updateBody);
await network.save();
return network;
} catch (err) {
console.error(err);
}
const network = await getNetworkById(networkId);
Object.assign(network, updateBody);
await network.save();
return network;
};

0 comments on commit d2c6ed8

Please sign in to comment.