Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/database/models/fileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ module.exports = (sequelize, DataTypes) => {
tenant_code: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: '',
},
},
{ sequelize, modelName: 'FileUpload', tableName: 'file_uploads', freezeTableName: true, paranoid: true }
Expand Down
39 changes: 14 additions & 25 deletions src/database/queries/fileUpload.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict'
const FileUpload = require('../models/index').FileUpload
const FileUpload = require('@database/models/index').FileUpload

exports.create = async (data) => {
try {
const createFileUpload = await FileUpload.create(data)
const result = createFileUpload.get({ plain: true })
return result
} catch (error) {
return error
throw error
}
}

Expand All @@ -19,7 +19,7 @@ exports.findOne = async (filter, options = {}) => {
raw: true,
})
} catch (error) {
return error
throw error
}
}

Expand All @@ -33,38 +33,27 @@ exports.update = async (filter, update, options = {}) => {

return res
} catch (error) {
return error
throw error
}
}

exports.listUploads = async (page, limit, status, organization_id) => {
exports.listUploads = async ({ page, limit, filter = {} } = {}) => {
try {
let filterQuery = {
where: {},
const result = await FileUpload.findAndCountAll({
where: filter,
attributes: {
exclude: ['created_at', 'updated_at', 'deleted_at', 'updated_by'],
},
offset: parseInt((page - 1) * limit, 10),
limit: parseInt(limit, 10),
}

if (organization_id) {
filterQuery.where.organization_id = organization_id
}

if (status) {
filterQuery.where.status = status
}
offset: (page - 1) * limit,
limit,
raw: true,
})

const result = await FileUpload.findAndCountAll(filterQuery)
const transformedResult = {
return {
count: result.count,
data: result.rows.map((row) => {
return row.get({ plain: true })
}),
data: result.rows,
}
return transformedResult
} catch (error) {
return error
throw error
}
}
1 change: 1 addition & 0 deletions src/services/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ module.exports = class AccountHelper {
const userSessionData = await userSessionsService.findUserSession(
{
id: decodedToken.data.session_id,
tenant_code: decodedToken.data.tenant_code,
},
{
attributes: ['refresh_token'],
Expand Down
15 changes: 9 additions & 6 deletions src/services/org-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,15 @@ module.exports = class OrgAdminHelper {
*/
static async getBulkInvitesFilesList(req) {
try {
let listFileUpload = await fileUploadQueries.listUploads(
req.pageNo,
req.pageSize,
req.query.status ? req.query.status : null,
req.decodedToken.organization_id
)
const listFileUpload = await fileUploadQueries.listUploads({
page: req.pageNo,
limit: req.pageSize,
filter: {
...(req.query.status && { status: req.query.status }),
organization_id: req.decodedToken.organization_id,
tenant_code: req.decodedToken.tenant_code,
},
})

if (listFileUpload.count > 0) {
await Promise.all(
Expand Down
2 changes: 1 addition & 1 deletion src/validators/v1/org-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
req.checkBody('upload_type')
.notEmpty()
.withMessage('upload_type is required')
.isIn()
.isIn(upload_type)
.withMessage(`upload_type must be from : ${upload_type.join(',')}`)
},
getRequestDetails: (req) => {
Expand Down