in backend/Functions/HTTP/game_listonmarketplace/app.js [29:69]
async function ListOnMarketplace(pk, sk, amount) {
const Key = { pk, sk };
try {
const getGame = await ddb.get({ TableName: playerInventoryTable, Key }).promise();
if (Object.prototype.hasOwnProperty.call(getGame, 'Item')) {
if (getGame.Item.quizMode === 'Run Anytime') {
console.error(`tried to sell single player game ${JSON.stringify(getGame.Item)}`);
return {
statusCode: 500,
body: JSON.stringify({ error: 'cannot sell single player game' }),
};
}
if (getGame.Item.usage !== 'unlimited') {
console.error(`tried to sell a purchased game ${JSON.stringify(getGame.Item)}`);
return {
statusCode: 500,
body: JSON.stringify({ error: 'cannot sell purchased game' }),
};
}
const { Item } = getGame;
Item.usage = 1;
Item.amount = amount;
//Updates for new Inventory Game table
Item.gameId = Item.sk;
Item.playerName = Item.pk;
delete(Item.pk);
delete(Item.sk);
//End updates for new Inventory Game table
const result = await ddb.put({ TableName: marketplaceTableName, Item }).promise();
return { statusCode: 200, body: JSON.stringify({ gameid: result.gameId }) };
}
console.error(`Could not find game in inventory ${JSON.stringify(Key)}`);
return { statusCode: 500, body: JSON.stringify({ error: 'could not find game in inventory' }) };
} catch (e) {
console.error(`Could not save game to marketplace ${JSON.stringify(e)}`);
return {
statusCode: 500,
body: JSON.stringify({ message: 'Could not save game to marketplace' }),
};
}
}