Skip to content

Commit 29c67c0

Browse files
authored
feat: add default feedback questions to opportunity (#3325)
1 parent 60f8a33 commit 29c67c0

5 files changed

Lines changed: 51 additions & 0 deletions

File tree

__tests__/private.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { OpportunityState } from '@dailydotdev/schema';
3030
import { generateShortId } from '../src/ids';
3131
import { OpportunityUser } from '../src/entity/opportunities/user';
3232
import { OpportunityUserType } from '../src/entity/opportunities/types';
33+
import { QuestionFeedback } from '../src/entity/questions/QuestionFeedback';
3334

3435
jest.mock('../src/common/geo', () => ({
3536
...(jest.requireActual('../src/common/geo') as Record<string, unknown>),
@@ -1246,6 +1247,17 @@ describe('POST /p/newOpportunity', () => {
12461247
expect(['javascript', 'typescript', 'react']).toEqual(
12471248
expect.arrayContaining(keywords.map((k) => k.keyword)),
12481249
);
1250+
1251+
const questionsFeedback = await con.getRepository(QuestionFeedback).find({
1252+
where: { opportunityId: opportunity?.id },
1253+
});
1254+
expect(questionsFeedback).toHaveLength(1);
1255+
1256+
expect(questionsFeedback[0]).toMatchObject({
1257+
opportunityId: opportunity?.id,
1258+
title: 'Why did you reject this opportunity?',
1259+
placeholder: `E.g., Not interested in the tech stack, location doesn't work for me, compensation too low...`,
1260+
});
12491261
});
12501262

12511263
it('should create opportunity with keywords and render markdown content', async () => {

__tests__/schema/opportunity.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5093,6 +5093,10 @@ describe('mutation parseOpportunity', () => {
50935093
title
50945094
placeholder
50955095
}
5096+
feedbackQuestions {
5097+
title
5098+
placeholder
5099+
}
50965100
}
50975101
}
50985102
`;
@@ -5203,6 +5207,12 @@ describe('mutation parseOpportunity', () => {
52035207
},
52045208
],
52055209
questions: [],
5210+
feedbackQuestions: [
5211+
{
5212+
title: 'Why did you reject this opportunity?',
5213+
placeholder: `E.g., Not interested in the tech stack, location doesn't work for me, compensation too low...`,
5214+
},
5215+
],
52065216
});
52075217

52085218
const opportunity = await con.getRepository(OpportunityJob).findOne({

src/common/opportunity/question.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { EntityManager } from 'typeorm';
2+
import { QuestionFeedback } from '../../entity/questions/QuestionFeedback';
3+
4+
export const addOpportunityDefaultQuestionFeedback = async ({
5+
entityManager,
6+
opportunityId,
7+
}: {
8+
entityManager: EntityManager;
9+
opportunityId: string;
10+
}): Promise<void> => {
11+
await entityManager.getRepository(QuestionFeedback).insert({
12+
opportunityId,
13+
title: 'Why did you reject this opportunity?',
14+
placeholder: `E.g., Not interested in the tech stack, location doesn't work for me, compensation too low...`,
15+
});
16+
};

src/routes/private.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { OpportunityJob } from '../entity/opportunities/OpportunityJob';
3030
import { OpportunityKeyword } from '../entity/OpportunityKeyword';
3131
import { logger } from '../logger';
3232
import { claimAnonOpportunities } from '../common/opportunity/user';
33+
import { addOpportunityDefaultQuestionFeedback } from '../common/opportunity/question';
3334

3435
interface SearchUsername {
3536
search: string;
@@ -152,10 +153,16 @@ export default async function (fastify: FastifyInstance): Promise<void> {
152153
.execute();
153154

154155
const id = opportunityJob.raw?.[0]?.id;
156+
155157
if (!id) {
156158
return res.status(500).send();
157159
}
158160

161+
await addOpportunityDefaultQuestionFeedback({
162+
entityManager,
163+
opportunityId: id,
164+
});
165+
159166
if (Array.isArray(keywords)) {
160167
await entityManager.getRepository(OpportunityKeyword).insert(
161168
keywords.map((keyword) => ({

src/schema/opportunity.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import { getBrokkrClient } from '../common/brokkr';
9090
import { garmScraperService } from '../common/scraper';
9191
import { Storage } from '@google-cloud/storage';
9292
import { randomUUID } from 'node:crypto';
93+
import { addOpportunityDefaultQuestionFeedback } from '../common/opportunity/question';
9394

9495
export interface GQLOpportunity
9596
extends Pick<
@@ -1843,6 +1844,11 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
18431844
} as DeepPartial<OpportunityJob>),
18441845
);
18451846

1847+
await addOpportunityDefaultQuestionFeedback({
1848+
entityManager,
1849+
opportunityId: opportunity.id,
1850+
});
1851+
18461852
await entityManager.getRepository(OpportunityKeyword).insert(
18471853
parsedOpportunity.keywords.map((keyword) => ({
18481854
opportunityId: opportunity.id,

0 commit comments

Comments
 (0)