Add custom serials

This commit is contained in:
Swift
2024-02-09 22:04:14 +03:30
parent ddb290241d
commit 7438a95166
9 changed files with 48 additions and 22 deletions
+18 -4
View File
@@ -254,15 +254,29 @@
/> />
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('serials-exel')" v-if="hasPermission('serials-exel')"
name="فایل اکسل شماره سریال گارانتی" name="اکسل سریال گارانتی(لوازم جانبی)"
:to="{ name: 'admin-serials-exel', query: { type: 'guaranteeSerial' } }" :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' } }" :to="{ name: 'admin-serials-exel', query: { type: 'orginality', g:1 } }"
font-icon="fal fa-file-excel"
exact
/>
<CSidebarNavItem
v-if="hasPermission('serials-exel')"
name="اکسل سریال گارانتی(لوازم صوتی)"
:to="{ name: 'admin-serials-exel', query: { type: 'guaranteeSerial', g:2 } }"
font-icon="fal fa-file-excel"
exact
/>
<CSidebarNavItem
v-if="hasPermission('serials-exel')"
name="اکسل سریال کالا(لوازم صوتی)"
:to="{ name: 'admin-serials-exel', query: { type: 'orginality', g:2 } }"
font-icon="fal fa-file-excel" font-icon="fal fa-file-excel"
exact exact
/> />
+12 -6
View File
@@ -30,17 +30,17 @@
download download
target="_blank" target="_blank"
title="برای دانلود کلیک کنید" title="برای دانلود کلیک کنید"
:href="scope.row.url + scope.row.name" :href="scope?.row.url + scope?.row.name"
style="color: blue; display: block; direction: ltr !important; text-align: right" style="color: blue; display: block; direction: ltr !important; text-align: right"
> >
{{ scope.row.name }} {{ scope?.row.name }}
</a> </a>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column v-if="scope.row.length > 1" label="حذف" width="60" align="left"> <el-table-column v-if="scope?.row.length > 1" label="حذف" width="60" align="left">
<template slot-scope="scope"> <template slot-scope="scope">
<CButton :key="scope.row._id" color="danger" variant="outline" @click="del(scope.row.name)"> <CButton :key="scope?.row._id" color="danger" variant="outline" @click="del(scope?.row.name)">
<i class="fal fa-trash-alt"></i> <i class="fal fa-trash-alt"></i>
</CButton> </CButton>
</template> </template>
@@ -60,9 +60,11 @@ export default {
async asyncData({ $axios, error, query }) { async asyncData({ $axios, error, query }) {
try { try {
const type = query?.type const type = query?.type
const g = query?.g
if (!type) throw new Error('invalid type') if (!type) throw new Error('invalid type')
const files = await $axios.get('/api/admin/serialExels', { const files = await $axios.get('/api/admin/serialExels', {
params: { type } params: { type, g }
}) })
return { return {
files: files.data files: files.data
@@ -74,7 +76,7 @@ export default {
}, },
data() { data() {
return { return {
files: null, files: [],
validation: {} validation: {}
} }
}, },
@@ -87,6 +89,9 @@ export default {
type() { type() {
return this.$route.query?.type return this.$route.query?.type
}, },
g() {
return this.$route.query?.g
},
title() { title() {
if (this.type === 'guaranteeSerial') return 'فایل اکسل شماره سریال گارانتی' if (this.type === 'guaranteeSerial') return 'فایل اکسل شماره سریال گارانتی'
else return 'فایل اکسل شماره سریال کالا' else return 'فایل اکسل شماره سریال کالا'
@@ -102,6 +107,7 @@ export default {
this.validation = {} this.validation = {}
const data = new FormData() const data = new FormData()
data.append('type', this.type) data.append('type', this.type)
data.append('g', this.g)
data.append('file', this.$refs.file.files[0]) data.append('file', this.$refs.file.files[0])
this.$axios this.$axios
.post('/api/admin/addExel', data) .post('/api/admin/addExel', data)
+3 -1
View File
@@ -132,6 +132,7 @@ export default {
inquiryType: 'guaranteeSerial', inquiryType: 'guaranteeSerial',
checkingSerial: false, checkingSerial: false,
brands:[], brands:[],
g: 1
} }
}, },
head() { head() {
@@ -178,7 +179,8 @@ export default {
this.checkingSerial = true this.checkingSerial = true
const data = { const data = {
serial: this.serial, serial: this.serial,
type: this.inquiryType type: this.inquiryType,
g: this.g
} }
const loading = this.$loading({ const loading = this.$loading({
lock: true, lock: true,
+12 -8
View File
@@ -27,9 +27,9 @@ module.exports.addExel = [
if (!req.files?.file.name.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item))) if (!req.files?.file.name.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item)))
return res.status(422).json({ validation: { file: { msg: 'فرمت فایل درست نمیباشد' } } }) return res.status(422).json({ validation: { file: { msg: 'فرمت فایل درست نمیباشد' } } })
const file = req.files.file const file = req.files.file
const { type } = req.body const { type, g } = req.body
try { try {
const path = type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
const files = await fs.readdirSync(path) const files = await fs.readdirSync(path)
for await (const item of files) { for await (const item of files) {
if (file.name === item) return res.status(422).json({ validation: { file: { msg: 'نام فایل تکراریست' } } }) if (file.name === item) return res.status(422).json({ validation: { file: { msg: 'نام فایل تکراریست' } } })
@@ -47,12 +47,14 @@ module.exports.addExel = [
module.exports.getAllExels = [ module.exports.getAllExels = [
(req, res) => { (req, res) => {
const type = req.query?.type const type = req.query?.type
if (!type) { const g = req.query?.g
if (!type || !g) {
res500(res, 'choose type') res500(res, 'choose type')
} }
const validValues = ['guaranteeSerial', 'orginality'] const validValues = ['guaranteeSerial', 'orginality']
if (!validValues.includes(type)) return res500(res, 'choose type') if (!validValues.includes(type)) return res500(res, 'choose type')
const path = type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
const downloadAblePath = type === 'guaranteeSerial' ? '/uploads/serials/' : '/uploads/serials_products/' const downloadAblePath = type === 'guaranteeSerial' ? '/uploads/serials/' : '/uploads/serials_products/'
fs.readdir(path, (err, files) => { fs.readdir(path, (err, files) => {
if (err) return res500(res, err) if (err) return res500(res, err)
@@ -67,10 +69,12 @@ module.exports.getAllExels = [
module.exports.removeExel = [ module.exports.removeExel = [
(req, res) => { (req, res) => {
const type = req.query?.type const type = req.query?.type
if (!type) return res500(res, 'choose type') const g = req.query?.g
if (!type || !g) return res500(res, 'choose type')
const validValues = ['guaranteeSerial', 'orginality'] const validValues = ['guaranteeSerial', 'orginality']
if (!validValues.includes(type)) return res500(res, 'choose type') if (!validValues.includes(type)) return res500(res, 'choose type')
const path = type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
fs.unlink(`${path}/${req.params.name}`, err => { fs.unlink(`${path}/${req.params.name}`, err => {
if (err) return res404(res, _faSr.not_found.item_id) if (err) return res404(res, _faSr.not_found.item_id)
else return res.json({ message: _faSr.response.success_remove }) else return res.json({ message: _faSr.response.success_remove })
@@ -95,8 +99,8 @@ module.exports.checkSerial = [
checkValidations(validationResult), checkValidations(validationResult),
async (req, res) => { async (req, res) => {
try { try {
const { serial, type } = req.body const { serial, type, g } = req.body
const serialStatus = await serialChecker(serial, type) const serialStatus = await serialChecker(serial, type, g)
let okMsg let okMsg
if (type === 'guaranteeSerial') okMsg = 'شماره سریال گارانتی معتبر میباشد.' if (type === 'guaranteeSerial') okMsg = 'شماره سریال گارانتی معتبر میباشد.'
+3 -3
View File
@@ -4,10 +4,10 @@ const readXlsxFile = require('read-excel-file/node')
const guaranteeSerialsPath = './static/uploads/serials' const guaranteeSerialsPath = './static/uploads/serials'
const productSerialsPath = './static/uploads/serials_products' const productSerialsPath = './static/uploads/serials_products'
const serialChecker = async (serial, type = 'guaranteeSerial') => { const serialChecker = async (serial, type = 'guaranteeSerial', g = 1) => {
let exelsPath let exelsPath
if (type === 'guaranteeSerial') exelsPath = guaranteeSerialsPath if (type === 'guaranteeSerial') exelsPath = guaranteeSerialsPath + g
if (type === 'orginality') exelsPath = productSerialsPath if (type === 'orginality') exelsPath = productSerialsPath + g
const lowerSerial = serial.toLowerCase() const lowerSerial = serial.toLowerCase()
// a promise to lowercase items and filter null or DateObjects // a promise to lowercase items and filter null or DateObjects