44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const BaseRepository = require('../../../src/database/repository');
|
|
const logger = require('../../../src/utils/logger');
|
|
|
|
class ResponseAnswerRepository extends BaseRepository {
|
|
constructor() {
|
|
super('pg_vt_response_answers');
|
|
}
|
|
|
|
/**
|
|
* Find answers with filters
|
|
* @param {Object} filters - Filter criteria
|
|
* @param {Object} options - Query options
|
|
*/
|
|
async findWithFilters(filters = {}, options = {}) {
|
|
const criteria = {};
|
|
|
|
if (filters.response_id) criteria.response_id = filters.response_id;
|
|
if (filters.question_id) criteria.question_id = filters.question_id;
|
|
|
|
const orderBy = options.orderBy || 'created_at';
|
|
const orderDirection = options.orderDirection || 'desc';
|
|
const limit = options.limit;
|
|
|
|
return await this.findAll(criteria, { orderBy, orderDirection, limit });
|
|
}
|
|
|
|
/**
|
|
* Create or update answer
|
|
* @param {Object} answerData - Answer data
|
|
*/
|
|
async save(answerData) {
|
|
if (answerData.id) {
|
|
return await this.updateById(answerData.id, {
|
|
...answerData,
|
|
updated_at: new Date().toISOString()
|
|
});
|
|
} else {
|
|
return await this.create(answerData);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = ResponseAnswerRepository;
|
|
|