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 with stage
in 1 minute and 55 seconds
export interface FAQDTO {
question: string;
answer: string;
position: number;
}
......@@ -49,7 +49,7 @@ function initParameterDataBase(): void {
console.log(err);
});
});
FAQ.sync();
FAQ.sync({ force: true });
}
export default { initParameterDataBase };
......@@ -16,6 +16,10 @@ FAQ.init({
answer: {
type: DataTypes.STRING,
},
position: {
type: DataTypes.INTEGER,
unique: true,
},
createdBy: {
type: DataTypes.INTEGER,
},
......
import FAQ from '../Models/FAQ';
import { Op } from 'sequelize';
import { FAQDTO } from '../DTOs/FAQDTO';
import FAQ from '../Models/FAQ';
const list = (): Promise<FAQ[]> => FAQ.findAll({
attributes: ['id', 'question', 'answer', 'createdAt'],
attributes: ['id', 'question', 'answer', 'position', 'createdAt'],
where: {
deletedAt: null,
},
order: ['position'],
});
const create = (createDto: FAQDTO): Promise<FAQ> => FAQ.create(createDto);
......@@ -20,9 +22,21 @@ const update = async (id: number, createDto: FAQDTO): Promise<FAQ | null> => {
if (!faq) {
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({
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