1+ import { Model , belongsTo , createServer , hasMany } from 'miragejs' ;
2+ import config from 'codecrafters-frontend/config/environment' ;
13import affiliateEarningsPayouts from './handlers/affiliate-earnings-payouts' ;
24import affiliateLinks from './handlers/affiliate-links' ;
35import affiliateReferrals from './handlers/affiliate-referrals' ;
@@ -16,7 +18,6 @@ import conceptEngagements from './handlers/concept-engagements';
1618import conceptGroups from './handlers/concept-groups' ;
1719import conceptQuestions from './handlers/concept-questions' ;
1820import concepts from './handlers/concepts' ;
19- import config from 'codecrafters-frontend/config/environment' ;
2021import contests from './handlers/contests' ;
2122import courseDefinitionUpdates from './handlers/course-definition-updates' ;
2223import courseExtensionActivations from './handlers/course-extension-activations' ;
@@ -69,53 +70,61 @@ import trustedCommunitySolutionEvaluations from './handlers/trusted-community-so
6970import upvotes from './handlers/upvotes' ;
7071import users from './handlers/users' ;
7172import views from './handlers/views' ;
72- import { Model , belongsTo , createServer , hasMany } from 'miragejs' ;
73- import { applyEmberDataSerializers , discoverEmberDataModels } from 'ember-cli-mirage' ;
7473
75- export default function ( config ) {
76- let finalConfig = {
77- ...config ,
78- models : {
79- ...discoverEmberDataModels ( config . store ) ,
80- ...config . models ,
81- ...{
82- courseStageComment : Model . extend ( {
83- user : belongsTo ( 'user' , { inverse : null } ) ,
84- target : belongsTo ( 'course-stage' , { inverse : 'comments' } ) ,
85- language : belongsTo ( 'language' , { inverse : null } ) ,
86- currentUserDownvotes : hasMany ( 'downvote' , { inverse : 'downvotable' } ) ,
87- currentUserUpvotes : hasMany ( 'upvote' , { inverse : 'upvotable' } ) ,
88- parentComment : belongsTo ( 'course-stage-comment' , { inverse : null } ) ,
89- } ) ,
90- communityCourseStageSolution : Model . extend ( {
91- comments : hasMany ( 'community-course-stage-solution-comment' , { inverse : 'target' } ) ,
92- courseStage : belongsTo ( 'course-stage' , { inverse : 'communitySolutions' } ) ,
93- currentUserDownvotes : hasMany ( 'downvote' , { inverse : 'downvotable' } ) ,
94- currentUserUpvotes : hasMany ( 'upvote' , { inverse : 'upvotable' } ) ,
95- evaluations : hasMany ( 'community-solution-evaluation' , { inverse : 'communitySolution' } ) ,
96- exports : hasMany ( 'community-solution-export' , { inverse : 'communitySolution' } ) ,
97- language : belongsTo ( 'language' , { inverse : null } ) ,
98- screencasts : hasMany ( 'course-stage-screencast' , { inverse : 'solution' } ) ,
99- trustedEvaluations : hasMany ( 'trusted-community-solution-evaluation' , { inverse : 'communitySolution' } ) ,
100- user : belongsTo ( 'user' , { inverse : null } ) ,
101- } ) ,
102- communityCourseStageSolutionComment : Model . extend ( {
103- user : belongsTo ( 'user' , { inverse : null } ) ,
104- target : belongsTo ( 'community-course-stage-solution' , { inverse : 'comments' } ) ,
105- language : belongsTo ( 'language' , { inverse : null } ) ,
106- currentUserDownvotes : hasMany ( 'downvote' , { inverse : 'downvotable' } ) ,
107- currentUserUpvotes : hasMany ( 'upvote' , { inverse : 'upvotable' } ) ,
108- parentComment : belongsTo ( 'community-course-stage-solution-comment' , { inverse : null } ) ,
109- } ) ,
110- fakeLogstream : Model . extend ( { } ) ,
74+ export default async function ( ) {
75+ if ( typeof FastBoot !== 'undefined' ) {
76+ return ;
77+ }
78+
79+ // This import MUST NOT happen under FastBoot, otherwise it'll cause major
80+ // errors when running `npm run start:fastboot`
81+ const { applyEmberDataSerializers, discoverEmberDataModels } = await import ( 'ember-cli-mirage' ) ;
82+
83+ return function ( config ) {
84+ const finalConfig = {
85+ ...config ,
86+ models : {
87+ ...discoverEmberDataModels ( config . store ) ,
88+ ...config . models ,
89+ ...{
90+ courseStageComment : Model . extend ( {
91+ user : belongsTo ( 'user' , { inverse : null } ) ,
92+ target : belongsTo ( 'course-stage' , { inverse : 'comments' } ) ,
93+ language : belongsTo ( 'language' , { inverse : null } ) ,
94+ currentUserDownvotes : hasMany ( 'downvote' , { inverse : 'downvotable' } ) ,
95+ currentUserUpvotes : hasMany ( 'upvote' , { inverse : 'upvotable' } ) ,
96+ parentComment : belongsTo ( 'course-stage-comment' , { inverse : null } ) ,
97+ } ) ,
98+ communityCourseStageSolution : Model . extend ( {
99+ comments : hasMany ( 'community-course-stage-solution-comment' , { inverse : 'target' } ) ,
100+ courseStage : belongsTo ( 'course-stage' , { inverse : 'communitySolutions' } ) ,
101+ currentUserDownvotes : hasMany ( 'downvote' , { inverse : 'downvotable' } ) ,
102+ currentUserUpvotes : hasMany ( 'upvote' , { inverse : 'upvotable' } ) ,
103+ evaluations : hasMany ( 'community-solution-evaluation' , { inverse : 'communitySolution' } ) ,
104+ exports : hasMany ( 'community-solution-export' , { inverse : 'communitySolution' } ) ,
105+ language : belongsTo ( 'language' , { inverse : null } ) ,
106+ screencasts : hasMany ( 'course-stage-screencast' , { inverse : 'solution' } ) ,
107+ trustedEvaluations : hasMany ( 'trusted-community-solution-evaluation' , { inverse : 'communitySolution' } ) ,
108+ user : belongsTo ( 'user' , { inverse : null } ) ,
109+ } ) ,
110+ communityCourseStageSolutionComment : Model . extend ( {
111+ user : belongsTo ( 'user' , { inverse : null } ) ,
112+ target : belongsTo ( 'community-course-stage-solution' , { inverse : 'comments' } ) ,
113+ language : belongsTo ( 'language' , { inverse : null } ) ,
114+ currentUserDownvotes : hasMany ( 'downvote' , { inverse : 'downvotable' } ) ,
115+ currentUserUpvotes : hasMany ( 'upvote' , { inverse : 'upvotable' } ) ,
116+ parentComment : belongsTo ( 'community-course-stage-solution-comment' , { inverse : null } ) ,
117+ } ) ,
118+ fakeLogstream : Model . extend ( { } ) ,
119+ } ,
111120 } ,
112- } ,
113- serializers : applyEmberDataSerializers ( config . serializers ) ,
114- routes,
115- trackRequests : config . environment === 'test' ,
116- } ;
121+ serializers : applyEmberDataSerializers ( config . serializers ) ,
122+ routes,
123+ trackRequests : config . environment === 'test' ,
124+ } ;
117125
118- return createServer ( finalConfig ) ;
126+ return createServer ( finalConfig ) ;
127+ } ;
119128}
120129
121130function routes ( ) {
0 commit comments