Compare commits
3 Commits
c0ba6a12b0
...
e4622f68b8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4622f68b8 | ||
|
|
2312fc3d75 | ||
|
|
e159858c88 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,8 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
*/node_modules/
|
*/node_modules/
|
||||||
*/build/
|
*/build/
|
||||||
|
|
||||||
|
**/node_modules/
|
||||||
|
**/build/
|
||||||
|
.DS_Store
|
||||||
|
.env
|
||||||
File diff suppressed because one or more lines are too long
@ -23,6 +23,11 @@ module.exports = class DocumentsDBApi {
|
|||||||
|
|
||||||
document_type: data.document_type
|
document_type: data.document_type
|
||||||
||
|
||
|
||||||
|
null
|
||||||
|
,
|
||||||
|
|
||||||
|
fileurl: data.fileurl
|
||||||
|
||
|
||||||
null
|
null
|
||||||
,
|
,
|
||||||
|
|
||||||
@ -52,6 +57,11 @@ module.exports = class DocumentsDBApi {
|
|||||||
document_type: item.document_type
|
document_type: item.document_type
|
||||||
||
|
||
|
||||||
null
|
null
|
||||||
|
,
|
||||||
|
|
||||||
|
fileurl: item.fileurl
|
||||||
|
||
|
||||||
|
null
|
||||||
,
|
,
|
||||||
|
|
||||||
importHash: item.importHash || null,
|
importHash: item.importHash || null,
|
||||||
@ -78,6 +88,8 @@ module.exports = class DocumentsDBApi {
|
|||||||
|
|
||||||
if (data.document_type !== undefined) updatePayload.document_type = data.document_type;
|
if (data.document_type !== undefined) updatePayload.document_type = data.document_type;
|
||||||
|
|
||||||
|
if (data.fileurl !== undefined) updatePayload.fileurl = data.fileurl;
|
||||||
|
|
||||||
updatePayload.updatedById = currentUser.id;
|
updatePayload.updatedById = currentUser.id;
|
||||||
|
|
||||||
await documents.update(updatePayload, {transaction});
|
await documents.update(updatePayload, {transaction});
|
||||||
@ -184,6 +196,17 @@ module.exports = class DocumentsDBApi {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filter.fileurl) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
[Op.and]: Utils.ilike(
|
||||||
|
'documents',
|
||||||
|
'fileurl',
|
||||||
|
filter.fileurl,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (filter.active !== undefined) {
|
if (filter.active !== undefined) {
|
||||||
where = {
|
where = {
|
||||||
...where,
|
...where,
|
||||||
|
|||||||
54
backend/src/db/migrations/1751472037865.js
Normal file
54
backend/src/db/migrations/1751472037865.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'documents',
|
||||||
|
'fileurl',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.TEXT,
|
||||||
|
|
||||||
|
},
|
||||||
|
{ transaction }
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
|
||||||
|
await queryInterface.removeColumn(
|
||||||
|
'documents',
|
||||||
|
'fileurl',
|
||||||
|
{ transaction }
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -38,6 +38,11 @@ document_type: {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fileurl: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
importHash: {
|
importHash: {
|
||||||
type: DataTypes.STRING(255),
|
type: DataTypes.STRING(255),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
|
|||||||
@ -79,6 +79,8 @@ require('./auth/auth');
|
|||||||
|
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
|
app.use('/uploads', express.static(path.join(__dirname, '../uploads')));
|
||||||
|
|
||||||
app.use('/api/auth', authRoutes);
|
app.use('/api/auth', authRoutes);
|
||||||
app.enable('trust proxy');
|
app.enable('trust proxy');
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,34 @@
|
|||||||
const util = require('util');
|
const util = require('util');
|
||||||
const Multer = require('multer');
|
const Multer = require('multer');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const maxSize = 10 * 1024 * 1024;
|
const maxSize = 10 * 1024 * 1024;
|
||||||
|
|
||||||
let processFile = Multer({
|
// Ensure uploads directory exists
|
||||||
storage: Multer.memoryStorage(),
|
const uploadDir = path.join(__dirname, '../../uploads');
|
||||||
limits: { fileSize: maxSize },
|
if (!fs.existsSync(uploadDir)) {
|
||||||
}).single("file");
|
fs.mkdirSync(uploadDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure disk storage
|
||||||
|
const storage = Multer.diskStorage({
|
||||||
|
destination: (req, file, cb) => cb(null, uploadDir),
|
||||||
|
filename: (req, file, cb) => {
|
||||||
|
const ext = path.extname(file.originalname);
|
||||||
|
const base = path.basename(file.originalname, ext);
|
||||||
|
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9);
|
||||||
|
cb(null, `${base}-${uniqueSuffix}${ext}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create multer instance
|
||||||
|
let processFile = Multer({
|
||||||
|
storage,
|
||||||
|
limits: { fileSize: maxSize },
|
||||||
|
}).single('file');
|
||||||
|
|
||||||
|
// Promisify for async/await
|
||||||
let processFileMiddleware = util.promisify(processFile);
|
let processFileMiddleware = util.promisify(processFile);
|
||||||
|
|
||||||
module.exports = processFileMiddleware;
|
module.exports = processFileMiddleware;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ const express = require('express');
|
|||||||
|
|
||||||
const DocumentsService = require('../services/documents');
|
const DocumentsService = require('../services/documents');
|
||||||
const DocumentsDBApi = require('../db/api/documents');
|
const DocumentsDBApi = require('../db/api/documents');
|
||||||
|
const processFile = require('../middlewares/upload');
|
||||||
const wrapAsync = require('../helpers').wrapAsync;
|
const wrapAsync = require('../helpers').wrapAsync;
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@ -20,6 +21,9 @@ const { parse } = require('json2csv');
|
|||||||
* title:
|
* title:
|
||||||
* type: string
|
* type: string
|
||||||
* default: title
|
* default: title
|
||||||
|
* fileurl:
|
||||||
|
* type: string
|
||||||
|
* default: fileurl
|
||||||
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -63,14 +67,28 @@ const { parse } = require('json2csv');
|
|||||||
* description: Invalid input data
|
* description: Invalid input data
|
||||||
* 500:
|
* 500:
|
||||||
* description: Some server error
|
* description: Some server error
|
||||||
*/
|
router.post('/', processFile, wrapAsync(async (req, res) => {
|
||||||
router.post('/', wrapAsync(async (req, res) => {
|
|
||||||
const referer = req.headers.referer || `${req.protocol}://${req.hostname}${req.originalUrl}`;
|
const referer = req.headers.referer || `${req.protocol}://${req.hostname}${req.originalUrl}`;
|
||||||
const link = new URL(referer);
|
const link = new URL(referer);
|
||||||
await DocumentsService.create(req.body.data, req.currentUser, true, link.host);
|
// Parse data from multipart/form-data or JSON
|
||||||
|
let data = {};
|
||||||
|
if (req.body.data) {
|
||||||
|
data = req.body.data;
|
||||||
|
} else {
|
||||||
|
data = {
|
||||||
|
title: req.body.title,
|
||||||
|
document_type: req.body.document_type,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Attach file URL if file was uploaded
|
||||||
|
if (req.file) {
|
||||||
|
data.fileurl = `/uploads/${req.file.filename}`;
|
||||||
|
}
|
||||||
|
await DocumentsService.create(data, req.currentUser, true, link.host);
|
||||||
const payload = true;
|
const payload = true;
|
||||||
res.status(200).send(payload);
|
res.status(200).send(payload);
|
||||||
}));
|
}));
|
||||||
|
}));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
@ -148,11 +166,24 @@ router.post('/bulk-import', wrapAsync(async (req, res) => {
|
|||||||
* required:
|
* required:
|
||||||
* - id
|
* - id
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
router.put('/:id', processFile, wrapAsync(async (req, res) => {
|
||||||
* description: The item data was successfully updated
|
// Parse data from multipart/form-data or JSON
|
||||||
* content:
|
let data = {};
|
||||||
* application/json:
|
if (req.body.data) {
|
||||||
* schema:
|
data = req.body.data;
|
||||||
|
} else {
|
||||||
|
data = {
|
||||||
|
title: req.body.title,
|
||||||
|
document_type: req.body.document_type,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Attach file URL if file was uploaded
|
||||||
|
if (req.file) {
|
||||||
|
data.fileurl = `/uploads/${req.file.filename}`;
|
||||||
|
}
|
||||||
|
await DocumentsService.update(data, req.params.id, req.currentUser);
|
||||||
|
res.status(200).send(true);
|
||||||
|
}));
|
||||||
* $ref: "#/components/schemas/Documents"
|
* $ref: "#/components/schemas/Documents"
|
||||||
* 400:
|
* 400:
|
||||||
* description: Invalid ID supplied
|
* description: Invalid ID supplied
|
||||||
@ -277,7 +308,7 @@ router.get('/', wrapAsync(async (req, res) => {
|
|||||||
req.query, { currentUser }
|
req.query, { currentUser }
|
||||||
);
|
);
|
||||||
if (filetype && filetype === 'csv') {
|
if (filetype && filetype === 'csv') {
|
||||||
const fields = ['id','title',
|
const fields = ['id','title','fileurl',
|
||||||
|
|
||||||
];
|
];
|
||||||
const opts = { fields };
|
const opts = { fields };
|
||||||
|
|||||||
@ -67,6 +67,8 @@ module.exports = class SearchService {
|
|||||||
|
|
||||||
"title",
|
"title",
|
||||||
|
|
||||||
|
"fileurl",
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
"inspections": [
|
"inspections": [
|
||||||
|
|||||||
1
frontend/json/runtimeError.json
Normal file
1
frontend/json/runtimeError.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@ -88,6 +88,15 @@ const CardDocuments = ({
|
|||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className='text-gray-500 dark:text-dark-600'>Fileurl</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{ item.fileurl }
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
</dl>
|
</dl>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -50,6 +50,11 @@ const ListDocuments = ({ documents, loading, onDelete, currentPage, numPages, on
|
|||||||
<p className={'line-clamp-2'}>{ item.file }</p>
|
<p className={'line-clamp-2'}>{ item.file }</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500'}>Fileurl</p>
|
||||||
|
<p className={'line-clamp-2'}>{ item.fileurl }</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
</Link>
|
</Link>
|
||||||
<ListActionsPopover
|
<ListActionsPopover
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
|
|||||||
@ -66,6 +66,19 @@ export const loadColumns = async (
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'fileurl',
|
||||||
|
headerName: 'Fileurl',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: true,
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
field: 'actions',
|
field: 'actions',
|
||||||
type: 'actions',
|
type: 'actions',
|
||||||
|
|||||||
@ -36,6 +36,8 @@ const EditDocuments = () => {
|
|||||||
|
|
||||||
document_type: '',
|
document_type: '',
|
||||||
|
|
||||||
|
'fileurl': '',
|
||||||
|
|
||||||
}
|
}
|
||||||
const [initialValues, setInitialValues] = useState(initVals)
|
const [initialValues, setInitialValues] = useState(initVals)
|
||||||
|
|
||||||
@ -111,6 +113,15 @@ const EditDocuments = () => {
|
|||||||
</Field>
|
</Field>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
label="Fileurl"
|
||||||
|
>
|
||||||
|
<Field
|
||||||
|
name="fileurl"
|
||||||
|
placeholder="Fileurl"
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
<BaseButtons>
|
<BaseButtons>
|
||||||
<BaseButton type="submit" color="info" label="Submit" />
|
<BaseButton type="submit" color="info" label="Submit" />
|
||||||
|
|||||||
@ -37,6 +37,8 @@ const EditDocumentsPage = () => {
|
|||||||
|
|
||||||
document_type: '',
|
document_type: '',
|
||||||
|
|
||||||
|
'fileurl': '',
|
||||||
|
|
||||||
}
|
}
|
||||||
const [initialValues, setInitialValues] = useState(initVals)
|
const [initialValues, setInitialValues] = useState(initVals)
|
||||||
|
|
||||||
@ -109,6 +111,15 @@ const EditDocumentsPage = () => {
|
|||||||
</Field>
|
</Field>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
label="Fileurl"
|
||||||
|
>
|
||||||
|
<Field
|
||||||
|
name="fileurl"
|
||||||
|
placeholder="Fileurl"
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
<BaseButtons>
|
<BaseButtons>
|
||||||
<BaseButton type="submit" color="info" label="Submit" />
|
<BaseButton type="submit" color="info" label="Submit" />
|
||||||
|
|||||||
@ -22,7 +22,7 @@ const DocumentsTablesPage = () => {
|
|||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const [filters] = useState([{label: 'Title', title: 'title'},
|
const [filters] = useState([{label: 'Title', title: 'title'},{label: 'Fileurl', title: 'fileurl'},
|
||||||
|
|
||||||
{label: 'DocumentType', title: 'document_type', type: 'enum', options: ['Checklist','Form','Policy','Procedure','Plan']},
|
{label: 'DocumentType', title: 'document_type', type: 'enum', options: ['Checklist','Form','Policy','Procedure','Plan']},
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -29,6 +29,8 @@ const initialValues = {
|
|||||||
|
|
||||||
document_type: 'Checklist',
|
document_type: 'Checklist',
|
||||||
|
|
||||||
|
fileurl: '',
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const DocumentsNew = () => {
|
const DocumentsNew = () => {
|
||||||
@ -82,6 +84,15 @@ const DocumentsNew = () => {
|
|||||||
</Field>
|
</Field>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
label="Fileurl"
|
||||||
|
>
|
||||||
|
<Field
|
||||||
|
name="fileurl"
|
||||||
|
placeholder="Fileurl"
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
<BaseButtons>
|
<BaseButtons>
|
||||||
<BaseButton type="submit" color="info" label="Submit" />
|
<BaseButton type="submit" color="info" label="Submit" />
|
||||||
|
|||||||
@ -22,7 +22,7 @@ const DocumentsTablesPage = () => {
|
|||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const [filters] = useState([{label: 'Title', title: 'title'},
|
const [filters] = useState([{label: 'Title', title: 'title'},{label: 'Fileurl', title: 'fileurl'},
|
||||||
|
|
||||||
{label: 'DocumentType', title: 'document_type', type: 'enum', options: ['Checklist','Form','Policy','Procedure','Plan']},
|
{label: 'DocumentType', title: 'document_type', type: 'enum', options: ['Checklist','Form','Policy','Procedure','Plan']},
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -59,6 +59,11 @@ const DocumentsView = () => {
|
|||||||
<p>{documents?.document_type ?? 'No data'}</p>
|
<p>{documents?.document_type ?? 'No data'}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Fileurl</p>
|
||||||
|
<p>{documents?.fileurl}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
|
|
||||||
<BaseButton
|
<BaseButton
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user