Skip to content
Snippets Groups Projects
Commit bf9dbfeb authored by Ramiro's avatar Ramiro
Browse files

Faqs dto, service, model

parent 03303c4c
No related branches found
No related tags found
No related merge requests found
Pipeline #16234 passed
export interface FAQDTO { export interface FAQDTO {
question: string; question: string;
answer: string; answer: string;
position: number;
} }
...@@ -49,7 +49,7 @@ function initParameterDataBase(): void { ...@@ -49,7 +49,7 @@ function initParameterDataBase(): void {
console.log(err); console.log(err);
}); });
}); });
FAQ.sync(); FAQ.sync({ force: true });
} }
export default { initParameterDataBase }; export default { initParameterDataBase };
...@@ -16,6 +16,10 @@ FAQ.init({ ...@@ -16,6 +16,10 @@ FAQ.init({
answer: { answer: {
type: DataTypes.STRING, type: DataTypes.STRING,
}, },
position: {
type: DataTypes.INTEGER,
unique: true,
},
createdBy: { createdBy: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
}, },
......
import FAQ from '../Models/FAQ'; import { Op } from 'sequelize';
import { FAQDTO } from '../DTOs/FAQDTO'; import { FAQDTO } from '../DTOs/FAQDTO';
import FAQ from '../Models/FAQ';
const list = (): Promise<FAQ[]> => FAQ.findAll({ const list = (): Promise<FAQ[]> => FAQ.findAll({
attributes: ['id', 'question', 'answer', 'createdAt'], attributes: ['id', 'question', 'answer', 'position', 'createdAt'],
where: { where: {
deletedAt: null, deletedAt: null,
}, },
order: ['position'],
}); });
const create = (createDto: FAQDTO): Promise<FAQ> => FAQ.create(createDto); const create = (createDto: FAQDTO): Promise<FAQ> => FAQ.create(createDto);
...@@ -20,9 +22,21 @@ const update = async (id: number, createDto: FAQDTO): Promise<FAQ | null> => { ...@@ -20,9 +22,21 @@ const update = async (id: number, createDto: FAQDTO): Promise<FAQ | null> => {
if (!faq) { if (!faq) {
return null; return null;
} }
const { question, answer } = createDto; const { question, answer, position } = createDto;
const positionFaq: FAQ | null = await FAQ.findOne({
where: {
id: {
[Op.ne]: id,
},
position,
deletedAt: null,
},
});
if (positionFaq) {
return null;
}
return faq.update({ return faq.update({
question, answer, question, answer, position,
}); });
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment