Skip to content

Commit

Permalink
Merge 065c834 into 08468c4
Browse files Browse the repository at this point in the history
  • Loading branch information
guilherme1guy committed Sep 16, 2021
2 parents 08468c4 + 065c834 commit 34a1bf7
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 11 deletions.
90 changes: 90 additions & 0 deletions data/createCommunity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[
{
"question": "Nome da comunidade",
"formName": "createCommunity"
},
{
"question": "Município",
"formName": "createCommunity"
},
{
"question": "Estado",
"formName": "createCommunity"
},
{
"question": "Há quanto tempo a comunidade existe?",
"formName": "createCommunity"
},
{
"question": "Quais são as características do território? (Localizado em área montanhosa? Área de floresta/plantação? É banhado por algum curso d’água? Alguma unidade de conservação?...)",
"formName": "createCommunity"
},
{
"question": "Qual é a área aproximada do território?",
"formName": "createCommunity"
},
{
"question": "O que existe de infraestrutura na comunidade?",
"formName": "createCommunity"
},
{
"question": "Quantas famílias vivem na comunidade?",
"formName": "createCommunity"
},
{
"question": "Existe uma liderança tradicional?",
"formName": "createCommunity"
},
{
"question": "Existe alguma organização representativa da comunidade? (associação, cooperativa, coletivo, movimento).",
"formName": "createCommunity"
},
{
"question": "Se sim, qual o nome da organização? Quando ela foi criada?",
"formName": "createCommunity"
},
{
"question": "Qual é o CNPJ da associação, caso seja registrada em cartório?",
"formName": "createCommunity"
},
{
"question": "Quais são as formas de uso da terra/território?",
"formName": "createCommunity"
},
{
"question": "Quais são as formas de produção?",
"formName": "createCommunity"
},
{
"question": "Quais são as fontes de renda das famílias na comunidade?",
"formName": "createCommunity"
},
{
"question": "Quais conflitos são enfrentados pela comunidade?",
"formName": "createCommunity"
},
{
"question": "Desde quando os conflitos ocorrem?",
"formName": "createCommunity"
},
{
"question": "Há histórico de vítimas?",
"formName": "createCommunity"
},
{
"question": "Nome completo",
"formName": "createCommunity"
},
{
"question": "Telefone",
"formName": "createCommunity"
},
{
"question": "Email",
"formName": "createCommunity"
},
{
"question": "Função na comunidade",
"formName": "createCommunity"
}
]
22 changes: 22 additions & 0 deletions data/getHelpForm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"question": "Nome completo",
"formName": "getHelpForm"
},
{
"question": "Email",
"formName": "getHelpForm"
},
{
"question": "Telefone",
"formName": "getHelpForm"
},
{
"question": "Nome da comunidade/povo tradicional/unidade social (nome cadastrado no aplicativo)",
"formName": "getHelpForm"
},
{
"question": "Escreva aqui sua dúvida ou comentário",
"formName": "getHelpForm"
}
]
3 changes: 3 additions & 0 deletions src/questionario/entities/questionario.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export type QuestionDocument = Question & Document;
export class Question {
@Prop()
question: string;

@Prop()
formName: string;
}

export const QuestionSchema = SchemaFactory.createForClass(Question);
9 changes: 7 additions & 2 deletions src/questionario/questionario.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SendSurveyAnswersDto } from './dto/sendSurveyAsnwers.dto';

@Controller()
export class QuestionController {
constructor(private readonly questionService: QuestionService) {}
constructor(private readonly questionService: QuestionService) { }

@MessagePattern('sendAnswers')
async create(@Payload() sendAnswers: SendSurveyAnswersDto) {
Expand All @@ -15,6 +15,11 @@ export class QuestionController {

@MessagePattern('getQuestionsToCreateCommunity')
async getQuestionsToCreateCommunity() {
return await this.questionService.getQuestionsToCreateCommunity();
return this.questionService.getQuestionsToCreateCommunity();
}

@MessagePattern('getQuestionsToGetHelp')
async getHelpQuestions() {
return this.questionService.getHelpQuestions();
}
}
12 changes: 10 additions & 2 deletions src/questionario/questionario.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class QuestionService {

@InjectModel('surveyQuestions')
private questionModel: Model<QuestionDocument>,
) {}
) { }

async saveAnswer(sendAnswers: SendSurveyAnswersDto) {
const answer = new this.answerModel(sendAnswers);
Expand All @@ -30,6 +30,14 @@ export class QuestionService {
}

async getQuestionsToCreateCommunity() {
return await this.questionModel.find({});

return this.questionModel.find({ 'formName': 'createCommunity' });;
}

async getHelpQuestions() {

return this.questionModel.find({ 'formName': 'getHelpForm' });;
}


}
27 changes: 20 additions & 7 deletions test/questionario/questionario.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ describe('QuestionService', () => {
{
provide: getModelToken('surveyQuestions'),
useValue: {
find: () => {
return [{ _id: '123123', question: 'Nome' }];
find: (data) => {
// data == { 'formName': 'createCommunity' }
let questions = [
{ _id: '1', question: 'Nome', formName: 'createCommunity' },
{ _id: '2', question: 'Nome', formName: 'getHelpForm' }
]

let found = questions.filter((element) => {
return element['formName'] === data['formName'];
});

return found;
},
},
},
Expand Down Expand Up @@ -56,12 +66,15 @@ describe('QuestionService', () => {
expect(await service.saveAnswer(answerData)).toStrictEqual(answerData);
});

it('should return questions', async () => {
it('should return create community questions', async () => {
expect(await service.getQuestionsToCreateCommunity()).toStrictEqual([
{
_id: '123123',
question: 'Nome',
},
{ _id: '1', question: 'Nome', formName: 'createCommunity' },
]);
});

it('should return get help questions', async () => {
expect(await service.getHelpQuestions()).toStrictEqual([
{ _id: '2', question: 'Nome', formName: 'getHelpForm' },
]);
});
});

0 comments on commit 34a1bf7

Please sign in to comment.