Skip to content

Commit

Permalink
Merge pull request #180 from VTTAssets/code_clean_5
Browse files Browse the repository at this point in the history
Page import: improve table promises
  • Loading branch information
MrPrimate committed May 30, 2020
2 parents 2281be1 + adb1f3d commit 6b35d3b
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/messaging/type/add/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,31 +251,33 @@ const addScenes = async (data) => {
}
};

const addRollTable = async (table, folder) => {
let rollTable = await RollTable.create({
name: table.name,
formula: `1d${table.max}`,
folder: folder._id,
flags: {
vtta: {
dndbeyond: {
rollTableId: table.id,
},
},
},
});
await rollTable.createEmbeddedEntity("TableResult", table.results);
return rollTable;
};

const addRollTables = async (data) => {
// folderName, rollTables, sourcebook) => {
const folderName = data.title;
const rollTables = data.rollTables;

let folder = await getFolder([folderName], "RollTable", data.book);
let tables = [];
for (let data of rollTables) {
console.log(data);
let rollTable = await RollTable.create({
name: data.name,
formula: `1d${data.max}`,
folder: folder._id,
flags: {
vtta: {
dndbeyond: {
rollTableId: data.id,
},
},
},
});
await rollTable.createEmbeddedEntity("TableResult", data.results);

tables.push(rollTable);
}
const tables = await Promise.all(rollTables.map(async (table) => {
return addRollTable(table, folder);
}));
return tables;
};

Expand Down

0 comments on commit 6b35d3b

Please sign in to comment.