-
Notifications
You must be signed in to change notification settings - Fork 55
feat(PM-577): apply for copilot opportunity #798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6163394
feat: apply for copilot opportunity
hentrymartin 0372f83
deploy pr branch to develo[
hentrymartin c608346
Merge branch 'develop' into PM-577
hentrymartin cffc8c0
updated swagger doc
hentrymartin bf83bcb
fix: removed validation
hentrymartin dc39219
fix: reference error
hentrymartin 22cc474
fix: model
hentrymartin 472acdf
fix: model
hentrymartin 5a0b44f
fix: model
hentrymartin 7c63711
fix: model
hentrymartin f0d083f
fix: model
hentrymartin aa60669
fix: model
hentrymartin 47664c8
fix: model
hentrymartin 1978a22
fix: validations
hentrymartin 3cac325
removed unnecessary file
hentrymartin 7ad57ec
fix: added notes column
hentrymartin 8dfcdf0
fix: added notes from request
hentrymartin 4a13b50
updated swagger file
hentrymartin 350d155
debug logs
hentrymartin c922d0c
added notes to model
hentrymartin c3e8fca
sanitize notes
hentrymartin 5329b81
sanitize notes
hentrymartin ca59b33
removed console log
hentrymartin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
migrations/umzug/migrations/20250411182312-copilot_opportunity_apply.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| up: async (queryInterface, Sequelize) => { | ||
| await queryInterface.createTable('copilot_applications', { | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| id: { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: false, | ||
| primaryKey: true, | ||
| autoIncrement: true, | ||
| }, | ||
| userId: { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: false, | ||
| }, | ||
| opportunityId: { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: false, | ||
| references: { | ||
| model: 'copilot_opportunities', | ||
| key: 'id', | ||
| }, | ||
| onUpdate: 'CASCADE', | ||
| onDelete: 'SET NULL', | ||
| }, | ||
| notes: { | ||
| type: Sequelize.TEXT, | ||
| allowNull: true, | ||
| }, | ||
| deletedAt: { | ||
| type: Sequelize.DATE, | ||
| allowNull: true, | ||
| }, | ||
| createdAt: { | ||
| type: Sequelize.DATE, | ||
| allowNull: true, | ||
| }, | ||
| updatedAt: { | ||
| type: Sequelize.DATE, | ||
| allowNull: true, | ||
| }, | ||
| deletedBy: { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: true, | ||
| }, | ||
| createdBy: { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: false, | ||
| }, | ||
| updatedBy: { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: false, | ||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| down: async (queryInterface) => { | ||
| await queryInterface.dropTable('copilot_applications'); | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import _ from 'lodash'; | ||
|
|
||
| module.exports = function defineCopilotOpportunity(sequelize, DataTypes) { | ||
| const CopilotApplication = sequelize.define('CopilotApplication', { | ||
| id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true }, | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| opportunityId: { | ||
| type: DataTypes.BIGINT, | ||
| allowNull: false, | ||
| references: { | ||
| model: 'copilot_opportunities', | ||
| key: 'id' | ||
| }, | ||
| onUpdate: 'CASCADE', | ||
| onDelete: 'CASCADE' | ||
| }, | ||
| notes: { | ||
| type: DataTypes.TEXT, | ||
| allowNull: true | ||
| }, | ||
| userId: { type: DataTypes.BIGINT, allowNull: false }, | ||
| deletedAt: { type: DataTypes.DATE, allowNull: true }, | ||
| createdAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW }, | ||
| updatedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW }, | ||
| deletedBy: { type: DataTypes.INTEGER, allowNull: true }, | ||
| createdBy: { type: DataTypes.INTEGER, allowNull: false }, | ||
| updatedBy: { type: DataTypes.INTEGER, allowNull: false }, | ||
| }, { | ||
| tableName: 'copilot_applications', | ||
| paranoid: true, | ||
| timestamps: true, | ||
| updatedAt: 'updatedAt', | ||
| createdAt: 'createdAt', | ||
| deletedAt: 'deletedAt', | ||
| indexes: [], | ||
| }); | ||
|
|
||
| CopilotApplication.associate = (models) => { | ||
| CopilotApplication.belongsTo(models.CopilotOpportunity, { as: 'copilotOpportunity', foreignKey: 'opportunityId' }); | ||
| }; | ||
|
|
||
| return CopilotApplication; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import _ from 'lodash'; | ||
| import validate from 'express-validation'; | ||
| import Joi from 'joi'; | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import models from '../../models'; | ||
| import util from '../../util'; | ||
| import { PERMISSION } from '../../permissions/constants'; | ||
| import { COPILOT_OPPORTUNITY_STATUS } from '../../constants'; | ||
|
|
||
| const applyCopilotRequestValidations = { | ||
| body: Joi.object().keys({ | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| notes: Joi.string(), | ||
| }), | ||
| }; | ||
|
|
||
| module.exports = [ | ||
| validate(applyCopilotRequestValidations), | ||
| async (req, res, next) => { | ||
| const { notes } = req.body; | ||
| const copilotOpportunityId = _.parseInt(req.params.id); | ||
| if (!util.hasPermissionByReq(PERMISSION.APPLY_COPILOT_OPPORTUNITY, req)) { | ||
| const err = new Error('Unable to apply for copilot opportunity'); | ||
| _.assign(err, { | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| details: JSON.stringify({ message: 'You do not have permission to apply for copilot opportunity' }), | ||
| status: 403, | ||
| }); | ||
| return next(err); | ||
| } | ||
|
|
||
| const data = { | ||
| userId: req.authUser.userId, | ||
| createdBy: req.authUser.userId, | ||
| updatedBy: req.authUser.userId, | ||
| opportunityId: copilotOpportunityId, | ||
| notes: notes ? req.sanitize(notes) : null, | ||
| }; | ||
|
|
||
| return models.CopilotOpportunity.findOne({ | ||
| where: { | ||
| id: copilotOpportunityId, | ||
| }, | ||
| }).then(async (opportunity) => { | ||
| if (!opportunity) { | ||
| const err = new Error('No opportunity found'); | ||
| err.status = 404; | ||
| return next(err); | ||
| } | ||
|
|
||
| if (opportunity.status !== COPILOT_OPPORTUNITY_STATUS.ACTIVE) { | ||
| const err = new Error('Opportunity is not active'); | ||
| err.status = 400; | ||
| return next(err); | ||
| } | ||
|
|
||
| const existingApplication = await models.CopilotApplication.findOne({ | ||
| where: { | ||
| opportunityId: opportunity.id, | ||
| userId: req.authUser.userId, | ||
| }, | ||
| }); | ||
|
|
||
| if (existingApplication) { | ||
| const err = new Error('User already applied for this opportunity'); | ||
| err.status = 400; | ||
| return next(err); | ||
| } | ||
|
|
||
| return models.CopilotApplication.create(data) | ||
| .then((result) => { | ||
| res.status(201).json(result); | ||
| return Promise.resolve(); | ||
| }) | ||
| .catch((err) => { | ||
| util.handleError('Error creating copilot application', err, req, next); | ||
| return next(err); | ||
| }); | ||
| }).catch((e) => { | ||
| util.handleError('Error applying for copilot opportunity', e, req, next); | ||
| }); | ||
| }, | ||
| ]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.