From 72ebd8b626f8fbb00f2eac428522a9318494b402 Mon Sep 17 00:00:00 2001 From: noctera Date: Sat, 9 Oct 2021 00:06:10 +0200 Subject: [PATCH] fix: error handling when package missing --- app/Services/ImportServiceProvider.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Services/ImportServiceProvider.js b/app/Services/ImportServiceProvider.js index cc43041a..f3af5f7e 100644 --- a/app/Services/ImportServiceProvider.js +++ b/app/Services/ImportServiceProvider.js @@ -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'); @@ -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( {