-
Notifications
You must be signed in to change notification settings - Fork 1
feature: add events module #12
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
Open
Ishaan-11
wants to merge
8
commits into
study-abacus:master
Choose a base branch
from
Ishaan-11:feature/add-events-module
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
20672ed
add: events model
4116608
add: events list api
52ebdd6
add: get events by id api
Ishaan-11 13b6c48
add: events admin crud api
Ishaan-11 78c7486
add: migration to add eventId in order and examAttempt
Ishaan-11 16734d8
handle eventId for orders
Ishaan-11 5130d0a
handle eventId for exam attempt
Ishaan-11 999f856
fix: order amount check
Ishaan-11 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| 'use strict'; | ||
|
|
||
| /** @type {import('sequelize-cli').Migration} */ | ||
| module.exports = { | ||
| async up(queryInterface, Sequelize) { | ||
| await queryInterface.createTable('events', { | ||
| id: { | ||
| type: Sequelize.BIGINT, | ||
| primaryKey: true, | ||
| autoIncrement: true, | ||
| allowNull: false, | ||
| }, | ||
| title: { | ||
| type: Sequelize.STRING, | ||
| allowNull: false, | ||
| }, | ||
| description: { | ||
| type: Sequelize.TEXT, | ||
| defaultValue: '', | ||
| allowNull: false, | ||
| }, | ||
| examinations: { | ||
| type: Sequelize.ARRAY(Sequelize.BIGINT), | ||
| allowNull: false, | ||
| }, | ||
| startDate: { | ||
| type: Sequelize.DATE, | ||
| allowNull: false, | ||
| }, | ||
| endDate: { | ||
| type: Sequelize.DATE, | ||
| allowNull: false, | ||
| }, | ||
| primaryPrice: { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: false, | ||
| }, | ||
| secondaryPrice: { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: false, | ||
| }, | ||
| createdAt: { | ||
| type: Sequelize.DATE, | ||
| allowNull: false, | ||
| }, | ||
| updatedAt: { | ||
| type: Sequelize.DATE, | ||
| allowNull: false, | ||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| async down(queryInterface, Sequelize) { | ||
| await queryInterface.dropTable('events'); | ||
| }, | ||
| }; |
32 changes: 32 additions & 0 deletions
32
api/migrations/20230806073635-add-eventid-to-orders-and-exam-attemp.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,32 @@ | ||
| 'use strict'; | ||
|
|
||
| /** @type {import('sequelize-cli').Migration} */ | ||
| module.exports = { | ||
| up: async (queryInterface, Sequelize) => { | ||
| return Promise.all([ | ||
| queryInterface.addColumn('orders', 'eventId', { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: false, | ||
| references: { | ||
| model: 'events', | ||
| key: 'id', | ||
| }, | ||
| }), | ||
| queryInterface.addColumn('examAttempts', 'eventId', { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: false, | ||
| references: { | ||
| model: 'events', | ||
| key: 'id', | ||
| }, | ||
| }), | ||
| ]); | ||
| }, | ||
|
|
||
| down: async (queryInterface, Sequelize) => { | ||
| return Promise.all([ | ||
| queryInterface.removeColumn('orders', 'eventId'), | ||
| queryInterface.removeColumn('examAttempts', 'eventId'), | ||
| ]); | ||
| }, | ||
| }; |
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,51 @@ | ||
| const JsonApiModel = require('base/jsonApiModel'); | ||
| const SerializerOpts = require('serializer-opts/event'); | ||
|
|
||
| class Event extends JsonApiModel { | ||
| static get serializerOpts() { | ||
| return SerializerOpts(this); | ||
| } | ||
|
|
||
| static associate() {} | ||
| } | ||
|
|
||
| module.exports = (sequelize, DataTypes) => { | ||
| Event.init( | ||
| { | ||
| title: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false, | ||
| }, | ||
| description: { | ||
| type: DataTypes.TEXT, | ||
| defaultValue: '', | ||
| allowNull: false, | ||
| }, | ||
| examinations: { | ||
| type: DataTypes.ARRAY(DataTypes.BIGINT), | ||
| allowNull: false, | ||
| }, | ||
| startDate: { | ||
| type: DataTypes.DATE, | ||
| allowNull: false, | ||
| }, | ||
| endDate: { | ||
| type: DataTypes.DATE, | ||
| allowNull: false, | ||
| }, | ||
| primaryPrice: { | ||
| type: DataTypes.BIGINT, | ||
| allowNull: false, | ||
| }, | ||
| secondaryPrice: { | ||
| type: DataTypes.BIGINT, | ||
| allowNull: false, | ||
| }, | ||
| }, | ||
| { | ||
| sequelize, | ||
| modelName: 'events', | ||
| }, | ||
| ); | ||
| return Event; | ||
| }; |
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,37 @@ | ||
| const BaseDetailController = require('base/controllers/detailController'); | ||
| const BaseCreateController = require('base/controllers/createController'); | ||
| const BaseUpdateController = require('base/controllers/updateController'); | ||
| const BaseDeleteController = require('base/controllers/deleteController'); | ||
| const DB = require('models'); | ||
| const EventSerializerOpts = require('serializer-opts/admin/event'); | ||
|
|
||
| class EventDetailController extends BaseDetailController { | ||
| model = DB.events; | ||
| modelName = DB.events.name; | ||
| serializerOpts = EventSerializerOpts(DB.events.name); | ||
| } | ||
|
|
||
| class EventDeleteController extends BaseDeleteController { | ||
| model = DB.events; | ||
| modelName = DB.events.name; | ||
| serializerOpts = EventSerializerOpts(DB.events.name); | ||
| } | ||
|
|
||
| class EventCreateController extends BaseCreateController { | ||
| model = DB.events; | ||
| modelName = DB.events.name; | ||
| serializerOpts = EventSerializerOpts(DB.events.name); | ||
| } | ||
|
|
||
| class EventUpdateController extends BaseUpdateController { | ||
| model = DB.events; | ||
| modelName = DB.events.name; | ||
| serializerOpts = EventSerializerOpts(DB.events.name); | ||
| } | ||
|
|
||
| module.exports = { | ||
| EventDetailController, | ||
| EventDeleteController, | ||
| EventCreateController, | ||
| EventUpdateController, | ||
| }; |
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,32 @@ | ||
| const AdminRoleRequired = require('hooks/admin-role-required'); | ||
| const Controllers = require('./controllers'); | ||
|
|
||
| module.exports = async (app, opts) => { | ||
| app.get( | ||
| '/:id', | ||
| { | ||
| preHandler: AdminRoleRequired, | ||
| }, | ||
| Controllers.EventDetailController.asHandler('get'), | ||
| ); | ||
|
|
||
| app.post( | ||
| '/', | ||
| { preHandler: AdminRoleRequired }, | ||
| Controllers.EventCreateController.asHandler('post'), | ||
| ); | ||
|
|
||
| app.patch( | ||
| '/:id', | ||
| { preHandler: AdminRoleRequired }, | ||
| Controllers.EventUpdateController.asHandler('patch'), | ||
| ); | ||
|
|
||
| app.delete( | ||
| '/:id', | ||
| { preHandler: AdminRoleRequired }, | ||
| Controllers.EventDeleteController.asHandler('delete'), | ||
| ); | ||
| }; | ||
|
|
||
| module.exports.autoPrefix = '/admin/events'; |
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,16 @@ | ||
| const BaseListController = require('base/controllers/listController'); | ||
| const BaseDetailController = require('base/controllers/detailController'); | ||
| const DB = require('models'); | ||
|
|
||
| class EventListController extends BaseListController { | ||
| model = DB.events; | ||
| } | ||
|
|
||
| class EventDetailController extends BaseDetailController { | ||
| model = DB.events; | ||
| } | ||
|
|
||
| module.exports = { | ||
| EventListController, | ||
| EventDetailController, | ||
| }; |
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,16 @@ | ||
| const Controllers = require('./controllers'); | ||
| const LoginRequired = require('hooks/login-required'); | ||
|
|
||
| module.exports = async (app, opts) => { | ||
| app.get('/', Controllers.EventListController.asHandler('get')); | ||
|
|
||
| app.get( | ||
| '/:id', | ||
| { | ||
| preHandler: [LoginRequired], | ||
| }, | ||
| Controllers.EventDetailController.asHandler('get'), | ||
| ); | ||
| }; | ||
|
|
||
| module.exports.autoPrefix = '/events'; |
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
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,12 @@ | ||
| module.exports = () => ({ | ||
| attributes: [ | ||
| 'id', | ||
| 'title', | ||
| 'description', | ||
| 'examinations', | ||
| 'startDate', | ||
| 'endDate', | ||
| 'primaryPrice', | ||
| 'secondaryPrice', | ||
| ], | ||
| }); |
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,15 @@ | ||
| module.exports = () => ({ | ||
| attributes: [ | ||
| 'id', | ||
| 'title', | ||
| 'description', | ||
| 'examinations', | ||
| 'startDate', | ||
| 'endDate', | ||
| 'primaryPrice', | ||
| 'secondaryPrice', | ||
| ], | ||
| meta: { | ||
| pagination: (records) => records.pagination, | ||
| }, | ||
| }); |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would need to check if event has expired or not based on
endDateThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has been already taken care inside
api/services/orders/index.js