Some icons changed, first implementation of contact edit
This commit is contained in:
@@ -41,4 +41,14 @@ export const changeTranslation = async (req, res) => {
|
||||
} catch(error) {
|
||||
res.status(403).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
export const getOpenContacts = async (req, res) => {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const openContacts = await AdminService.getOpenContacts(userId);
|
||||
res.status(200).json(openContacts);
|
||||
} catch (error) {
|
||||
res.status(403).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,11 @@ const ContactMessage = sequelize.define('contact_message', {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false
|
||||
},
|
||||
isFinished: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
}
|
||||
}, {
|
||||
tableName: 'contact_message',
|
||||
timestamps: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router } from 'express';
|
||||
import { authenticate } from '../middleware/authMiddleware.js';
|
||||
import { getOpenInterests, changeInterest, deleteInterest, changeTranslation } from '../controllers/adminController.js';
|
||||
import { getOpenInterests, changeInterest, deleteInterest, changeTranslation, getOpenContacts } from '../controllers/adminController.js';
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -9,4 +9,6 @@ router.post('/interest', authenticate, changeInterest);
|
||||
router.post('/interest/translation', authenticate, changeTranslation);
|
||||
router.delete('/interest/:id', authenticate, deleteInterest);
|
||||
|
||||
router.get('/opencontacts', authenticate, getOpenContacts);
|
||||
|
||||
export default router;
|
||||
@@ -4,13 +4,11 @@ import InterestType from "../models/type/interest.js"
|
||||
import InterestTranslationType from "../models/type/interest_translation.js"
|
||||
import User from "../models/community/user.js";
|
||||
import UserParamValue from "../models/type/user_param_value.js";
|
||||
import ContactMessage from "../models/service/contactmessage.js";
|
||||
|
||||
class AdminService {
|
||||
async hasUserAccess(userId, section) {
|
||||
const userRights = await UserRight.findAll({
|
||||
/* where: {
|
||||
userId: userId,
|
||||
},*/
|
||||
include: [{
|
||||
model: UserRightType,
|
||||
as: 'rightType',
|
||||
@@ -119,6 +117,18 @@ class AdminService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getOpenContacts(userId) {
|
||||
if (!this.hasUserAccess(userId, 'contacts')) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const openContacts = await ContactMessage.findAll({
|
||||
where: {
|
||||
isFinished: false,
|
||||
}
|
||||
})
|
||||
return openContacts;
|
||||
}
|
||||
}
|
||||
|
||||
export default new AdminService();
|
||||
Reference in New Issue
Block a user