4108-mdb_backend #987

Merged
juan merged 9 commits from 4108-mdb_backend into dev 2022-06-02 07:33:24 +00:00
3 changed files with 19 additions and 30 deletions
Showing only changes of commit 8340041b33 - Show all commits

View File

@ -2585,10 +2585,4 @@ INSERT INTO `vn`.`mdbBranch` (`name`)
INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`)
VALUES
('tpv', 'test', '1'),
('lab', 'master', '1'),
('enc', 'test', '1'),
('ent', 'master', '1'),
('com', 'test', '1'),
('eti', 'master', '1'),
('ser', 'test', '1'),
('lib', 'master', '1');
('lab', 'master', '1');

View File

@ -104,7 +104,7 @@
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./storage/access",
"maxFileSize": "2621440000",
"maxFileSize": "524288000",
alexm marked this conversation as resolved Outdated
Outdated
Review

Fica màxim 500MB, crec que el valor està en bytes, comprova-ho en la documentació de looback storage.

Fica màxim 500MB, crec que el valor està en bytes, comprova-ho en la documentació de looback storage.
"allowedContentTypes": [
"application/x-7z-compressed"
]

View File

@ -1,5 +1,6 @@
const fs = require('fs-extra');
const path = require('path');
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('upload', {
@ -68,16 +69,21 @@ module.exports = Self => {
const destinationFile = path.join(
accessContainer.client.root, accessContainer.name, appName, `${newVersion}.7z`);
if (process.env.NODE_ENV == 'test') {
try {
await fs.unlink(srcFile);
} catch (e) {}
} else {
if (process.env.NODE_ENV == 'test')
alexm marked this conversation as resolved Outdated
Outdated
Review

Lleva el try/catch, si intenta borrar el fitxer i no pot, ha de tornar el error.

Lleva el try/catch, si intenta borrar el fitxer i no pot, ha de tornar el error.
await fs.unlink(srcFile);
else {
await fs.move(srcFile, destinationFile, {
overwrite: true
});
await fs.chmod(destinationFile, 0o644);
const existBranch = await models.MdbBranch.findOne({
where: {name: branch}
alexm marked this conversation as resolved Outdated
Outdated
Review

Abans de crear el directori, comprovar que la rama existeix en la taula mdbBranch, en cas contrari llançar un error notificant que la rama no existeix

Abans de crear el directori, comprovar que la rama existeix en la taula mdbBranch, en cas contrari llançar un error notificant que la rama no existeix
});
if (!existBranch)
throw new UserError('Not exist this branch');
const branchPath = path.join(accessContainer.client.root, 'branches', branch);
alexm marked this conversation as resolved
Review

Es necesari borrarlo primer? fs.symlink no el reescriu si existeix?

Es necesari borrarlo primer? fs.symlink no el reescriu si existeix?
await fs.mkdir(branchPath, {recursive: true});
@ -96,28 +102,17 @@ module.exports = Self => {
}
}
const version = await models.MdbVersion.findOne({
where: {
app: appName,
branchFk: branch
}
}, myOptions);
if (!version) {
return await models.MdbVersion.create({
app: appName,
branchFk: branch,
version: newVersion
});
}
await version.updateAttributes({version: newVersion}, myOptions);
await models.MdbVersion.upsert({
app: appName,
alexm marked this conversation as resolved Outdated
Outdated
Review

Pots gastar upsert, aixina en menys codi insertes (si no existeix) o actualitzes.

https://loopback.io/doc/en/lb3/Creating-updating-and-deleting-data.html

Pots gastar upsert, aixina en menys codi insertes (si no existeix) o actualitzes. https://loopback.io/doc/en/lb3/Creating-updating-and-deleting-data.html
branchFk: branch,
version: newVersion
});
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
if (await fs.stat(srcFile))
if (fs.existsSync(srcFile))
await fs.unlink(srcFile);
throw e;