New serial reader system
This commit is contained in:
@@ -30,7 +30,7 @@ module.exports.addExel = [
|
|||||||
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)
|
const data = await creator(exelFile, type, g, file.name)
|
||||||
|
|
||||||
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
|
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
|
||||||
const files = await fs.readdirSync(path)
|
const files = await fs.readdirSync(path)
|
||||||
@@ -74,7 +74,7 @@ module.exports.getAllExels = [
|
|||||||
|
|
||||||
|
|
||||||
module.exports.removeExel = [
|
module.exports.removeExel = [
|
||||||
(req, res) => {
|
async (req, res) => {
|
||||||
const type = req.query?.type
|
const type = req.query?.type
|
||||||
const g = req.query?.g
|
const g = req.query?.g
|
||||||
|
|
||||||
@@ -82,6 +82,8 @@ module.exports.removeExel = [
|
|||||||
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) + `/${g}`
|
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
|
||||||
|
await Serial.deleteMany({ fileName: req.params.name })
|
||||||
|
|
||||||
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 })
|
||||||
@@ -127,7 +129,7 @@ module.exports.checkSerial = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const creator = (exel, type, g) => {
|
const creator = (exel, type, g, name) => {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
for (const row of exel) {
|
for (const row of exel) {
|
||||||
@@ -141,6 +143,7 @@ const creator = (exel, type, g) => {
|
|||||||
serial.message = row[2]
|
serial.message = row[2]
|
||||||
serial.type = type
|
serial.type = type
|
||||||
serial.kind = g
|
serial.kind = g
|
||||||
|
serial.fileName = name
|
||||||
serial.save()
|
serial.save()
|
||||||
} else {
|
} else {
|
||||||
await Serial.create(
|
await Serial.create(
|
||||||
@@ -149,6 +152,7 @@ const creator = (exel, type, g) => {
|
|||||||
model: row[0],
|
model: row[0],
|
||||||
message: row[2],
|
message: row[2],
|
||||||
type,
|
type,
|
||||||
|
fileName: name,
|
||||||
kind: g
|
kind: g
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ const SerialSchema = mongoose.Schema({
|
|||||||
kind:{
|
kind:{
|
||||||
type:Number,
|
type:Number,
|
||||||
enum:[2,1]
|
enum:[2,1]
|
||||||
}
|
},
|
||||||
|
fileName:String
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user