Skip to content

Commit

Permalink
fix: error handling when package missing
Browse files Browse the repository at this point in the history
  • Loading branch information
noctera committed Oct 8, 2021
1 parent 077cf61 commit 72ebd8b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/Services/ImportServiceProvider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Group, VocabularyCard, Translation, Drawer, sequelize } = require('../../database');
const { Group, LanguagePackage, VocabularyCard, Translation, Drawer, sequelize } = require('../../database');
const ApiError = require('../utils/ApiError.js');
const httpStatus = require('http-status');
const { createDrawers } = require('./DrawerServiceProvider.js');
Expand All @@ -14,6 +14,17 @@ async function storeGroupVocabulary(
) {
const transaction = await sequelize.transaction();

const languagePackage = await LanguagePackage.findOne({
where: {
userId,
id: languagePackageId,
},
});

if (!languagePackage) {
throw new ApiError(httpStatus.NOT_FOUND, 'language package not found');
}

try {
const group = await Group.create(
{
Expand Down

0 comments on commit 72ebd8b

Please sign in to comment.