fix: bug in inserting guarantee serial and originality serial

This commit is contained in:
mahyargdz
2025-02-19 10:05:44 +03:30
parent 119b10c73b
commit 9a9e28dd55
5 changed files with 34 additions and 44 deletions
+9 -17
View File
@@ -76,7 +76,7 @@
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('brands')" v-if="hasPermission('brands')"
name="لیست برند ها" name="لیست برند ها"
:to="{ name: 'admin-brands'}" :to="{ name: 'admin-brands' }"
font-icon="fal fa-file-alt" font-icon="fal fa-file-alt"
:exact="false" :exact="false"
/> />
@@ -89,9 +89,6 @@
font-icon="fas fa-folder" font-icon="fas fa-folder"
@update:show="val => setDropdownState('adminS_CustomerM_Dropdown', val)" @update:show="val => setDropdownState('adminS_CustomerM_Dropdown', val)"
> >
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('customers')" v-if="hasPermission('customers')"
name="لیست مشتریان" name="لیست مشتریان"
@@ -255,28 +252,28 @@
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('serials-exel')" v-if="hasPermission('serials-exel')"
name="اکسل سریال گارانتی(لوازم جانبی)" name="اکسل سریال گارانتی(لوازم جانبی)"
:to="{ name: 'admin-serials-exel', query: { type: 'guaranteeSerial', g:1 } }" :to="{ name: 'admin-serials-exel', query: { type: 'guaranteeSerial', g: 1 } }"
font-icon="fal fa-file-excel" font-icon="fal fa-file-excel"
exact exact
/> />
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('serials-exel')" v-if="hasPermission('serials-exel')"
name="اکسل سریال کالا(لوازم جانبی)" name="اکسل سریال اصالت(لوازم جانبی)"
:to="{ name: 'admin-serials-exel', query: { type: 'orginality', g:1 } }" :to="{ name: 'admin-serials-exel', query: { type: 'orginality', g: 1 } }"
font-icon="fal fa-file-excel" font-icon="fal fa-file-excel"
exact exact
/> />
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('serials-exel')" v-if="hasPermission('serials-exel')"
name="اکسل سریال گارانتی(لوازم صوتی)" name="اکسل سریال گارانتی(لوازم صوتی)"
:to="{ name: 'admin-serials-exel', query: { type: 'guaranteeSerial', g:2 } }" :to="{ name: 'admin-serials-exel', query: { type: 'guaranteeSerial', g: 2 } }"
font-icon="fal fa-file-excel" font-icon="fal fa-file-excel"
exact exact
/> />
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('serials-exel')" v-if="hasPermission('serials-exel')"
name="اکسل سریال کالا(لوازم صوتی)" name="اکسل سریال اصالت(لوازم صوتی)"
:to="{ name: 'admin-serials-exel', query: { type: 'orginality', g:2 } }" :to="{ name: 'admin-serials-exel', query: { type: 'orginality', g: 2 } }"
font-icon="fal fa-file-excel" font-icon="fal fa-file-excel"
exact exact
/> />
@@ -321,7 +318,7 @@
v-if="hasPermission('gps')" v-if="hasPermission('gps')"
:show="getDropdownState('adminS_GpsM_Dropdown')" :show="getDropdownState('adminS_GpsM_Dropdown')"
name="مدیریت پنل جی پی اس" name="مدیریت پنل جی پی اس"
:font-icon="getDropdownState('adminS_GpsM_Dropdown') ? `fas fa-folder-open`:`fas fa-folder` " :font-icon="getDropdownState('adminS_GpsM_Dropdown') ? `fas fa-folder-open` : `fas fa-folder`"
@update:show="val => setDropdownState('adminS_GpsM_Dropdown', val)" @update:show="val => setDropdownState('adminS_GpsM_Dropdown', val)"
> >
<CSidebarNavItem <CSidebarNavItem
@@ -340,7 +337,6 @@
:badge="pendingUsers ? { text: pendingUsers, color: 'danger' } : null" :badge="pendingUsers ? { text: pendingUsers, color: 'danger' } : null"
/> />
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('gps')" v-if="hasPermission('gps')"
name="دستگاه ها" name="دستگاه ها"
@@ -354,17 +350,15 @@
:to="{ name: 'admin-gps-installed-device', query: { filter: 'all' } }" :to="{ name: 'admin-gps-installed-device', query: { filter: 'all' } }"
font-icon="fal fa-map" font-icon="fal fa-map"
:badge="newInstallDeviceRequest ? { text: newInstallDeviceRequest, color: 'danger' } : null" :badge="newInstallDeviceRequest ? { text: newInstallDeviceRequest, color: 'danger' } : null"
:exact="false" :exact="false"
/> />
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('gps')" v-if="hasPermission('gps')"
name="درخواست های برداشت" name="درخواست های برداشت"
:to="{ name: 'admin-gps-withdraw', query: { filter: 'all' }}" :to="{ name: 'admin-gps-withdraw', query: { filter: 'all' } }"
font-icon="fal fa-credit-card" font-icon="fal fa-credit-card"
:exact="false" :exact="false"
:badge="newWithdrawRequest ? { text: newWithdrawRequest, color: 'danger' } : null" :badge="newWithdrawRequest ? { text: newWithdrawRequest, color: 'danger' } : null"
/> />
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('gps')" v-if="hasPermission('gps')"
@@ -380,10 +374,8 @@
font-icon="fal fa-trophy" font-icon="fal fa-trophy"
:exact="false" :exact="false"
:badge="newAwardRequest ? { text: newAwardRequest, color: 'danger' } : null" :badge="newAwardRequest ? { text: newAwardRequest, color: 'danger' } : null"
/> />
</CSidebarNavDropdown> </CSidebarNavDropdown>
</CSidebarNav> </CSidebarNav>
<!-- sidebar content --> <!-- sidebar content -->
+12 -15
View File
@@ -25,11 +25,12 @@ module.exports.addExel = [
checkValidations(validationResult), checkValidations(validationResult),
async (req, res) => { async (req, res) => {
if (!req.files?.file) return res.status(422).json({ validation: { file: { msg: 'فایل را اضافه کنید' } } }) if (!req.files?.file) return res.status(422).json({ validation: { file: { msg: 'فایل را اضافه کنید' } } })
if (!req.files?.file.name.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item))) return res.status(422).json({ validation: { file: { msg: 'فرمت فایل درست نمیباشد' } } }) if (!req.files?.file.name.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item)))
return res.status(422).json({ validation: { file: { msg: 'فرمت فایل درست نمیباشد' } } })
const file = req.files.file const file = req.files.file
const { type, g } = req.body const { type, g } = req.body
try { try {
const exelFile = await readXlsxFile(Buffer.from(file.data)); const exelFile = await readXlsxFile(Buffer.from(file.data))
const data = await creator(exelFile, type, g, file.name) const data = await creator(exelFile, type, g, file.name)
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}` const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
@@ -42,8 +43,6 @@ module.exports.addExel = [
// res.status(201).json({ msg: _sr.fa.response.success_save, data }) // res.status(201).json({ msg: _sr.fa.response.success_save, data })
res.status(201).json(data) res.status(201).json(data)
} catch (err) { } catch (err) {
return res500(res, err) return res500(res, err)
} }
@@ -72,7 +71,6 @@ module.exports.getAllExels = [
} }
] ]
module.exports.removeExel = [ module.exports.removeExel = [
async (req, res) => { async (req, res) => {
const type = req.query?.type const type = req.query?.type
@@ -110,18 +108,19 @@ module.exports.checkSerial = [
try { try {
const { serial, type, g } = req.body const { serial, type, g } = req.body
const code = serial.toString().trim().toLowerCase() const code = serial.toString().trim().toLowerCase()
console.log(code)
const serialStatus = await Serial.findOne({ const serialStatus = await Serial.findOne({
code, code,
type, type,
kind: g kind: g
}) })
console.log(serialStatus)
if (!serialStatus) { if (!serialStatus) {
res404(res, 'این کد در سامانه وجود ندارد') res404(res, 'این کد در سامانه وجود ندارد')
} else { } else {
res.status(200).json({ message: serialStatus.message }) res.status(200).json({ message: serialStatus.message })
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
return res500(res, e) return res500(res, e)
@@ -135,9 +134,9 @@ const creator = (exel, type, g, name) => {
for (const row of exel) { for (const row of exel) {
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
const code = row[1].toString().trim().toLowerCase() const code = row[1].toString().trim().toLowerCase()
const serial = await Serial.findOne({ code }) const serial = await Serial.findOne({ code, type, kind: g })
if (serial) { if (serial) {
console.info("Repeated serial ", row[1]) console.info('Repeated serial => ', row[1])
serial.model = row[0] serial.model = row[0]
serial.message = row[2] serial.message = row[2]
@@ -146,22 +145,20 @@ const creator = (exel, type, g, name) => {
serial.fileName = name serial.fileName = name
serial.save() serial.save()
} else { } else {
await Serial.create( console.log('inserting new =>', row[1])
{ await Serial.create({
code, code,
model: row[0], model: row[0],
message: row[2], message: row[2],
type, type,
fileName: name, fileName: name,
kind: g kind: g
})
} }
)
} }
resolve('end')
}
resolve("end")
} catch (error) { } catch (error) {
console.log(error); console.log(error)
reject(error.message) reject(error.message)
} }
+4 -3
View File
@@ -73,7 +73,7 @@ module.exports.add_transaction = [
] ]
return msgArray.join(' ') return msgArray.join(' ')
} }
// TODO: here arpa service
if (agent === 'main') { if (agent === 'main') {
const ArpaResponse = await saveTransactionToArpa(data, items, db_name) const ArpaResponse = await saveTransactionToArpa(data, items, db_name)
await TransactionDraft.findByIdAndRemove(draftId) await TransactionDraft.findByIdAndRemove(draftId)
@@ -140,7 +140,7 @@ module.exports.get_all_transactions_for_agent = [
async (req, res) => { async (req, res) => {
try { try {
const { agent_id } = req const { agent_id } = req
const transactions = await Transaction.find({ agent_id }).sort({created_at:-1}) const transactions = await Transaction.find({ agent_id }).sort({ created_at: -1 })
return res.json(transactions) return res.json(transactions)
} catch (e) { } catch (e) {
return res500(res, e) return res500(res, e)
@@ -291,7 +291,8 @@ module.exports.change_transaction_status_by_agent = [
module.exports.get_all_agents_inbox_for_admin = [ module.exports.get_all_agents_inbox_for_admin = [
async (req, res) => { async (req, res) => {
try { try {
const transactions = await Transaction.find().sort({created_at:-1}) const transactions = await Transaction.find()
.sort({ created_at: -1 })
.populate('agent_id', 'agent_code full_name') .populate('agent_id', 'agent_code full_name')
.populate('user_id', 'province_id province_name city_id city_name') .populate('user_id', 'province_id province_name city_id city_name')
return res.json(transactions) return res.json(transactions)