refs #6184 saveCmr #1788
|
@ -49,8 +49,12 @@ module.exports = Self => {
|
|||
try {
|
||||
for (let id of ids) {
|
||||
if (zipConfig && totalSize > zipConfig.maxSize) throw new UserError('Files are too large');
|
||||
|
||||
const baseUrl = (ctx.req.headers.origin)
|
||||
? `${ctx.req.headers.origin}/api`
|
||||
guillermo marked this conversation as resolved
Outdated
|
||||
: `${ctx.req.headers.referer}api`
|
||||
const response = await axios.get(
|
||||
`${ctx.req.headers.referer}api/Routes/${id}/cmr?access_token=${token.id}`, {
|
||||
`${baseUrl}/Routes/${id}/cmr?access_token=${token.id}`, {
|
||||
...myOptions,
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
"name": "Cmr",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "cmr"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"id": true,
|
||||
"description": "Identifier"
|
||||
},
|
||||
"truckPlate": {
|
||||
"type": "number"
|
||||
},
|
||||
"observations": {
|
||||
"type": "string"
|
||||
},
|
||||
"senderInstrucctions": {
|
||||
"type": "string"
|
||||
},
|
||||
"paymentInstruccions": {
|
||||
"type": "string"
|
||||
},
|
||||
"specialAgreements": {
|
||||
"type": "string"
|
||||
},
|
||||
"created": {
|
||||
"type": "date"
|
||||
},
|
||||
"companyFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"addressToFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"addressFromFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"supplierFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"packagesList": {
|
||||
"type": "string"
|
||||
},
|
||||
"merchandiseDetail": {
|
||||
"type": "string"
|
||||
},
|
||||
"landed": {
|
||||
"type": "date"
|
||||
},
|
||||
"ead": {
|
||||
"type": "date"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@ module.exports = Self => {
|
|||
Self.saveCmr = async(ctx, tickets, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
let tx, dms;
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
@ -32,42 +32,43 @@ module.exports = Self => {
|
|||
|
||||
try {
|
||||
for (const ticketId of tickets) {
|
||||
const cmrFk = await models.Ticket.findOne({
|
||||
where: {id: ticketId},
|
||||
fields: ['cmrFk']
|
||||
}, myOptions);
|
||||
const ticket = await models.Ticket.findById(ticketId, myOptions);
|
||||
|
||||
if (cmrFk) {
|
||||
const dmsTypeCmr = await models.DmsType.findOne({
|
||||
where: {code: 'ticket'},
|
||||
if (ticket.cmrFk) {
|
||||
const dmsType = await models.DmsType.findOne({
|
||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
Este el cree cada vegada pero es el mateix id per a tots. Pujal fora del for Este el cree cada vegada pero es el mateix id per a tots. Pujal fora del for
El nom jo posaría dmsTypeCmr
|
||||
where: {code: 'cmr'},
|
||||
fields: ['id']
|
||||
}, myOptions);
|
||||
|
||||
const hasDmsCmr = await models.TicketDms.findOne({
|
||||
where: { ticketFk: ticketId },
|
||||
fields: ['dmsFk'],
|
||||
include: {
|
||||
relation: 'dms',
|
||||
fields: ['dmsFk'],
|
||||
scope: {
|
||||
where: { dmsTypeFk: dmsTypeCmr }
|
||||
where: { dmsTypeFk: dmsType.id }
|
||||
}
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
if (!hasDmsCmr) {
|
||||
const zip = await models.Route.downloadCmrsZip(ctx, cmr, myOptions);
|
||||
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
||||
const ctxUploadFile = Object.assign({}, zip);
|
||||
if (!hasDmsCmr.dms()) {
|
||||
const zip = await models.Route.downloadCmrsZip(ctx, ticket.cmrFk.toString(), myOptions);
|
||||
let ctxUploadFile;
|
||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
const const
guillermo
commented
En eixe cas te que ser let, fijat baix. En eixe cas te que ser let, fijat baix.
Per a que siga const he tingut que juntar-ho.
|
||||
ctx.req.file = Object.assign({}, zip);
|
||||
ctxUploadFile = Object.assign({}, ctx);
|
||||
ctxUploadFile.args = {
|
||||
warehouseId: ticket.warehouseFk,
|
||||
companyId: ticket.companyFk,
|
||||
dmsTypeId: dmsTypeCmr.id,
|
||||
dmsTypeId: dmsType.id,
|
||||
reference: '',
|
||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
si es dms, en reference posa ticket.cmrFk si es dms, en reference posa ticket.cmrFk
|
||||
description: `Documento comprimido - CMR ${cmrFk}`,
|
||||
description: `Documento comprimido - CMR ${ticket.cmrFk}`,
|
||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
al ser el tipo cmr, no es neceario poner cmr, pueden buscar por tipo al ser el tipo cmr, no es neceario poner cmr, pueden buscar por tipo
quitar texto en español.
Propuesta: poner cmr: cmrFk, ticket: ticketFk
|
||||
hasFile: false
|
||||
};
|
||||
dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
||||
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
|
||||
const dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
||||
await models.TicketDms.create({
|
||||
ticketFk: ticketId,
|
||||
dmsFk: dms[0].id
|
||||
}, myOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,6 +139,11 @@
|
|||
"type": "belongsTo",
|
||||
"model": "Zone",
|
||||
"foreignKey": "zoneFk"
|
||||
},
|
||||
"cmrFk": {
|
||||
"type": "belongsTo",
|
||||
"model": "Cmr",
|
||||
"foreignKey": "cmrFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
No he gastat mai .referer, pero crec que es millor gastar la funcio que crea pablo encomter de ctx.req.headers.origin
back/methods/url/getUrl.js
El problema es que no quiero el "/#!/", ya que quiero apuntar a la API