Last active
November 27, 2020 10:21
-
-
Save megganeturner/a4ad75bca57006664e88689c7af977d0 to your computer and use it in GitHub Desktop.
Raisely Code Challenge
This file contains 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
import Adapter from "@ember-data/adapter"; | |
import { run } from "@ember/runloop"; | |
import RSVP from "rsvp"; | |
import $ from "jquery"; | |
export default class User extends Adapter { | |
createRecord(store, type, snapshot) { | |
let data = this.serialize(snapshot, { includeId: true }); | |
return new RSVP.Promise(function (resolve, reject) { | |
$.ajax({ | |
type: "POST", | |
url: "https://api.raisely.com/v3/signup", | |
dataType: "json", | |
data: data | |
}).then( | |
function (data) { | |
run(null, resolve, data); | |
}, | |
function (jqXHR) { | |
jqXHR.then = null; // tame jQuery's ill mannered promises | |
run(null, reject, jqXHR); | |
} | |
); | |
}); | |
} | |
// queryRecord(store, type, query) { | |
// // return fetch('/api/current_user'); | |
// } | |
// validate: | |
// https://api.raisely.com/v3/check-user | |
// post: | |
// https://api.raisely.com/v3/signup | |
} |
This file contains 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
import Controller from '@ember/controller'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
} |
This file contains 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
import Controller from "@ember/controller"; | |
import { inject } from '@ember/service'; | |
export default Controller.extend({ | |
// store: inject(), | |
userFirstName: "TestingFirst", | |
userLastName: "TestingLast", | |
userEmail: "[email protected]", | |
userPassword: "chicken", | |
actions: { | |
createUser: function () { | |
const firstName = this.get("userFirstName"); | |
const lastName = this.get("userLastName"); | |
const email = this.get("userEmail"); | |
const password = this.get("userPassword"); | |
console.log(Store); | |
const user = this.store.createRecord("user", { | |
firstName: firstName, | |
lastName: lastName, | |
email: email, | |
// obviously in a real app we wouldn't be sending the password as plain text | |
password: password | |
}); | |
user.save(); | |
} | |
} | |
}); |
This file contains 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
// import Model from 'ember-data/model'; | |
// /* | |
// import attr from 'ember-data/attr'; | |
// import { belongsTo, hasMany } from 'ember-data/relationships'; | |
// */ | |
// export default class extends Model { | |
// } | |
import Model, { attr } from "@ember-data/model"; | |
export default class UserModel extends Model { | |
@attr campaignUuid; | |
@attr data; | |
@attr firstName; | |
@attr lastName; | |
@attr email; | |
@attr password; | |
} |
This file contains 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
import EmberRouter from '@ember/routing/router'; | |
import config from './config/environment'; | |
const Router = EmberRouter.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('index', { path: '/' }); | |
this.route('signup'); | |
}); | |
export default Router; |
This file contains 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
import Route from "@ember/routing/route"; | |
export default class SignupRoute extends Route { | |
model() { | |
// return ['Marie Curie', 'Mae Jemison', 'Albert Hofmann']; | |
} | |
} |
This file contains 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
import Serializer from "@ember-data/serializer"; | |
export default Serializer.extend({ | |
// normalizeResponse (store, ModelClass, payload, id, requestType) { | |
// const partiallyNormalised = normalizeSinglePayload(payload); | |
// return this._super(store, ModelClass, partiallyNormalised, id, requestType); | |
// }, | |
normalizeResponse(store, schema, rawPayload) { | |
console.log(rawPayload); | |
return rawPayload; | |
}, | |
serialize(snapshot, options) { | |
const serializedResource = { | |
id: snapshot.id, | |
type: snapshot.modelName, | |
attributes: snapshot.attributes() | |
}; | |
return serializedResource; | |
} | |
}); | |
// import EmberObject from '@ember/object'; | |
// export default class ApplicationSerializer extends EmberObject { | |
// normalizeResponse(store, schema, rawPayload) { | |
// return rawPayload; | |
// } | |
// serialize(snapshot, options) { | |
// const serializedResource = { | |
// id: snapshot.id, | |
// type: snapshot.modelName, | |
// attributes: snapshot.attributes() | |
// }; | |
// return serializedResource; | |
// } | |
// } |
This file contains 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
@import "routes/signup.css"; | |
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} |
This file contains 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
.signup-panel { | |
width: 50vw; | |
max-width: 400px; | |
margin: 50px auto; | |
display: flex; | |
flex-direction: column; | |
font-family: sans-serif; | |
} |
This file contains 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
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment