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

Add support for indexing collection:destroy command #34

Merged
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const {
Logger,
MySQL: { getTableInstance },
} = require('lisk-service-framework');

const config = require('../../../../config');

const logger = Logger();

const MYSQL_ENDPOINT = config.endpoints.mysql;
const collectionsTableSchema = require('../../../database/schema/collections');

const getCollectionsTable = () => getTableInstance(
collectionsTableSchema.tableName,
collectionsTableSchema,
MYSQL_ENDPOINT,
);

// Command specific constants
const COMMAND_NAME = 'destroy';

// eslint-disable-next-line no-unused-vars
const applyTransaction = async (blockHeader, tx, events, dbTrx) => {
const collectionsTable = await getCollectionsTable();
const [collectionNFT] = await collectionsTable.find(
{ collectionID: tx.params.collectionID },
['collectionID'],
dbTrx,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer directly deleting the entry, instead of finding and deleting.


logger.trace(`Deleting collection with ID ${collectionNFT.collectionID}.`);
await collectionsTable.delete(collectionNFT, dbTrx);
logger.debug(`Deleted collection with ID ${collectionNFT.collectionsID}.`);
};

// eslint-disable-next-line no-unused-vars
const revertTransaction = async (blockHeader, tx, events, dbTrx) => {};

module.exports = {
COMMAND_NAME,
applyTransaction,
revertTransaction,
};