From 3f25ed051dba08c0280c8dc3235797ddeccd67d1 Mon Sep 17 00:00:00 2001 From: Bouncey Date: Sat, 16 Feb 2019 11:37:52 +0000 Subject: [PATCH] chore: Remove unused files --- api-server/common/models/flyer.json | 32 ----- api-server/common/models/job.json | 119 ------------------- api-server/common/models/promo.js | 84 ------------- api-server/common/models/promo.json | 59 --------- api-server/common/models/story.json | 81 ------------- api-server/common/resource/academicPolicy.js | 27 ----- api-server/common/utils/jsonp$.js | 74 ------------ api-server/common/utils/wait-for-epics.js | 15 --- api-server/server/boot/sitemap.js | 61 ---------- 9 files changed, 552 deletions(-) delete mode 100644 api-server/common/models/flyer.json delete mode 100644 api-server/common/models/job.json delete mode 100644 api-server/common/models/promo.js delete mode 100644 api-server/common/models/promo.json delete mode 100644 api-server/common/models/story.json delete mode 100644 api-server/common/resource/academicPolicy.js delete mode 100644 api-server/common/utils/jsonp$.js delete mode 100644 api-server/common/utils/wait-for-epics.js delete mode 100644 api-server/server/boot/sitemap.js diff --git a/api-server/common/models/flyer.json b/api-server/common/models/flyer.json deleted file mode 100644 index fd5b6c5172..0000000000 --- a/api-server/common/models/flyer.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "flyer", - "base": "PersistedModel", - "idInjection": true, - "trackChanges": false, - "properties": { - "message": { - "type": "string" - }, - "isActive": { - "type": "boolean", - "default": true - } - }, - "validations": [], - "relations": {}, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ], - "methods": {} -} diff --git a/api-server/common/models/job.json b/api-server/common/models/job.json deleted file mode 100644 index 288d26b82f..0000000000 --- a/api-server/common/models/job.json +++ /dev/null @@ -1,119 +0,0 @@ -{ - "name": "job", - "base": "PersistedModel", - "strict": true, - "idInjection": true, - "trackChanges": false, - "properties": { - "id": { - "type": "string", - "id": true - }, - "position": { - "type": "string" - }, - "company": { - "type": "string" - }, - "logo": { - "type": "string" - }, - "city": { - "type": "string" - }, - "email": { - "type": "string", - "required": true - }, - "phone": { - "type": "string" - }, - "state": { - "type": "string" - }, - "url": { - "type": "string" - }, - "country": { - "type": "string" - }, - "locale": { - "type": "string", - "required": true, - "description": "format: city, state" - }, - "location": { - "type": "geopoint", - "description": "location in lat, long" - }, - "description": { - "type": "string" - }, - "isApproved": { - "type": "boolean", - "default": false - }, - "isHighlighted": { - "type": "boolean", - "default": false - }, - "isPaid": { - "type": "boolean", - "default": false - }, - "isFilled": { - "type": "boolean", - "default": false - }, - "postedOn": { - "type": "date", - "defaultFn": "now" - }, - "isFrontEndCert": { - "type": "boolean", - "description": "Camper must be front end certified to apply", - "defaut": false - }, - "isBackEndCert": { - "type": "boolean", - "description": "Camper must be back end certified to apply", - "default": false - }, - "isFullStackCert": { - "type": "boolean", - "description": "Camper must be full stack certified to apply", - "default": false - }, - "isRemoteOk": { - "type": "boolean", - "description": "Camper may work remotely", - "default": false - }, - "howToApply": { - "type": "string", - "required": true, - "description": "How campers apply to a job" - }, - "promoCodeUsed": { - "type": "string", - "description": "The promocode, if any, that the job uses" - } - }, - "validations": [], - "relations": {}, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ], - "methods": {} -} diff --git a/api-server/common/models/promo.js b/api-server/common/models/promo.js deleted file mode 100644 index c561914bc9..0000000000 --- a/api-server/common/models/promo.js +++ /dev/null @@ -1,84 +0,0 @@ -import { isAlphanumeric, isMongoId } from 'validator'; -import debug from 'debug'; - -const log = debug('fcc:models:promo'); - -export default function promo(Promo) { - Promo.getButton = function getButton(id, code, type = 'isNot') { - const Job = Promo.app.models.Job; - if (!id || !isMongoId('' + id)) { - return Promise.reject(new Error( - 'Must include job id' - )); - } - - if ( - !isAlphanumeric('' + code) && - type && - !isAlphanumeric('' + type) - ) { - return Promise.reject(new Error( - 'Code or Type should be an alphanumeric' - )); - } - - const query = { - where: { - and: [{ - code: type === 'isNot' ? type : 'isHighlighted' - }, - { - type: type.replace(/^\$/g, '') - }] - } - }; - - return Promo.findOne(query) - .then(function(promo) { - // turn promo model to plain js object; - promo = promo.toJSON(); - return Job.updateAll({ id: id }, { promoCodeUsed: code }) - .then(function({ count = 0 } = {}) { - log('job', count); - if (count) { - return { - ...promo, - name: `${code} Discount` - }; - } - return Promise.reject(new Error( - `Job ${id} not found` - )); - }); - }); - }; - - Promo.remoteMethod( - 'getButton', - { - description: 'Get button id for promocode', - accepts: [ - { - arg: 'id', - type: 'string', - required: true - }, - { - arg: 'code', - type: 'string', - required: true - }, - { - arg: 'type', - type: 'string' - } - ], - returns: [ - { - arg: 'promo', - type: 'object' - } - ] - } - ); -} diff --git a/api-server/common/models/promo.json b/api-server/common/models/promo.json deleted file mode 100644 index eef51eb129..0000000000 --- a/api-server/common/models/promo.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "name": "promo", - "base": "PersistedModel", - "strict": true, - "idInjection": true, - "trackChanges": false, - "properties": { - "code": { - "type": "string", - "required": true, - "description": "The code to unlock the promotional discount" - }, - "name": { - "type": "string", - "required": true, - "description": "The name of the discount" - }, - "buttonId": { - "type": "string", - "required": true, - "description": "The ID of the paypal button" - }, - "type": { - "type": "string", - "description": "A selector of different types of buttons for the same discount" - }, - "fullPrice": { - "type": "number", - "required": true, - "description": "The original amount" - }, - "discountAmount": { - "type": "number", - "description": "The amount of the discount if applicable" - }, - "discountPercent": { - "type": "number", - "description": "The amount of the discount as a percentage if applicable" - } - }, - "validations": [], - "relations": {}, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "EXECUTE", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW", - "property": "getButton" - } - ], - "methods": {} -} diff --git a/api-server/common/models/story.json b/api-server/common/models/story.json deleted file mode 100644 index dd8650fba6..0000000000 --- a/api-server/common/models/story.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "name": "story", - "base": "PersistedModel", - "idInjection": true, - "trackChanges": false, - "properties": { - "id": { - "type": "string", - "id": true - }, - "name": { - "type": "string", - "index": { - "mongodb": { - "unique": true, - "background": true - } - } - }, - "headline": { - "type": "string" - }, - "timePosted": { - "type": "number", - "default": 0 - }, - "link": { - "type": "string" - }, - "metaDescription": { - "type": "string", - "default": "" - }, - "description": { - "type": "string" - }, - "rank": { - "type": "number", - "default": 0 - }, - "upVotes": { - "type": "array", - "default": [] - }, - "author": { - "type": {} - }, - "image": { - "type": "string", - "default": "" - }, - "storyLink": { - "type": "string", - "default": "" - } - }, - "validations": [], - "relations": {}, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - }, - { - "accessType": "EXECUTE", - "principalType": "ROLE", - "principalId": "$authenticated", - "permission": "ALLOW", - "property": "create" - } - ], - "methods": {} -} diff --git a/api-server/common/resource/academicPolicy.js b/api-server/common/resource/academicPolicy.js deleted file mode 100644 index 6f2a7cb43e..0000000000 --- a/api-server/common/resource/academicPolicy.js +++ /dev/null @@ -1,27 +0,0 @@ -const policy = [ - 'Before you can claim a verified certification, you must accept the ' + - 'Academic Honesty Policy below.', - 'I understand that plagiarism means copying someone else’s work and ' + - 'presenting the work as if it were my own, without clearly attributing ' + - 'the original author.', - 'I understand that plagiarism is an act of intellectual dishonesty, and ' + - 'that people usually get kicked out of university or fired from their ' + - 'jobs if they get caught plagiarizing.', - 'Aside from using open source libraries such as jQuery and Bootstrap, ' + - 'and short snippets of code which are clearly attributed to their ' + - 'original author, 100% of the code in my projects was written by me, or ' + - 'along with another camper with whom I was pair programming in real time.', - 'I pledge that I did not plagiarize any of my freeCodeCamp work. ' + - 'I understand that freeCodeCamp’s team will audit my projects ' + - 'to confirm this.', - 'In the situations where we discover instances of unambiguous plagiarism, ' + - 'we will replace the camper in question’s certification with a message ' + - 'that "Upon review, this account has been flagged for academic dishonesty."', - 'As an academic institution that grants achievement-based certifications, ' + - 'we take academic honesty very seriously. If you have any questions about ' + - 'this policy, or suspect that someone has violated it, you can email ' + - 'team@freecodecamp.org and we ' + - 'will investigate.' -]; - -export default policy; diff --git a/api-server/common/utils/jsonp$.js b/api-server/common/utils/jsonp$.js deleted file mode 100644 index febcbf7ade..0000000000 --- a/api-server/common/utils/jsonp$.js +++ /dev/null @@ -1,74 +0,0 @@ -import { AnonymousObservable, Disposable } from 'rx'; - -const root = typeof window !== 'undefined' ? window : {}; -const trash = 'document' in root && root.document.createElement('div'); - -function destroy(element) { - trash.appendChild(element); - trash.innerHTML = ''; -} - -export function jsonp$(options) { - let id = 0; - if (typeof options === 'string') { - options = { url: options }; - } - - return new AnonymousObservable(function(o) { - const settings = { - jsonp: 'JSONPCallback', - async: true, - jsonpCallback: 'rxjsjsonpCallbackscallback_' + (id++).toString(36), - ...options - }; - - let script = root.document.createElement('script'); - script.type = 'text/javascript'; - script.async = settings.async; - script.src = settings.url.replace(settings.jsonp, settings.jsonpCallback); - - root[settings.jsonpCallback] = function(data) { - root[settings.jsonpCallback].called = true; - root[settings.jsonpCallback].data = data; - }; - - const handler = function(e) { - if (e.type === 'load' && !root[settings.jsonpCallback].called) { - e = { type: 'error' }; - } - const status = e.type === 'error' ? 400 : 200; - const data = root[settings.jsonpCallback].data; - - if (status === 200) { - o.onNext({ - status: status, - responseType: 'jsonp', - response: data, - originalEvent: e - }); - - o.onCompleted(); - } else { - o.onError({ - type: 'error', - status: status, - originalEvent: e - }); - } - }; - - script.onload = script.onreadystatechanged = script.onerror = handler; - - const head = root.document.getElementsByTagName('head')[0] || - root.document.documentElement; - - head.insertBefore(script, head.firstChild); - - return Disposable.create(() => { - script.onload = script.onreadystatechanged = script.onerror = null; - - destroy(script); - script = null; - }); - }); -} diff --git a/api-server/common/utils/wait-for-epics.js b/api-server/common/utils/wait-for-epics.js deleted file mode 100644 index f847de16b7..0000000000 --- a/api-server/common/utils/wait-for-epics.js +++ /dev/null @@ -1,15 +0,0 @@ -import { Observable } from 'rx'; -import debug from 'debug'; - -const log = debug('redux-epic:waitForEpics'); - -// waitForEpics(epicMiddleware: EpicMiddleware) => Observable[Void] -export default function waitForEpics(epicMiddleware) { - return Observable.defer(() => { - log('calling actions onCompleted'); - epicMiddleware.end(); - return Observable.merge(epicMiddleware); - }) - .last({ defaultValue: null }) - .map(() => epicMiddleware.restart()); -} diff --git a/api-server/server/boot/sitemap.js b/api-server/server/boot/sitemap.js deleted file mode 100644 index eba41d10a8..0000000000 --- a/api-server/server/boot/sitemap.js +++ /dev/null @@ -1,61 +0,0 @@ -import moment from 'moment'; -import { Scheduler, Observable } from 'rx'; -import { timeCache, observeQuery } from '../utils/rx'; -import { dasherize } from '../utils'; - -const cacheTimeout = [ 24, 'hours' ]; -const appUrl = 'https://www.freecodecamp.org'; - -// getCachedObservable( -// app: ExpressApp, -// modelName: String, -// nameProp: String, -// blockProp: String, -// map: (nameProp: String) => String -// ) => Observable[models] -function getCachedObservable(app, modelName, nameProp, blockProp, map) { - return observeQuery( - app.models[modelName], - 'find', - { fields: { [nameProp]: true, [blockProp]: true } } - ) - .flatMap(models => { - return Observable.from(models, null, null, Scheduler.default); - }) - .filter(model => !!model[nameProp] && !!model[blockProp]) - .map(map ? map : (x) => x) - .toArray() - ::timeCache(cacheTimeout[0], cacheTimeout[1]); -} - -export default function sitemapRouter(app) { - const router = app.loopback.Router(); - const challengeProps = ['dashedName', 'block']; - const challenges$ = getCachedObservable(app, 'Challenge', ...challengeProps); - const stories$ = getCachedObservable(app, 'Story', 'storyLink', dasherize); - function sitemap(req, res, next) { - const now = moment(new Date()).format('YYYY-MM-DD'); - return Observable.combineLatest( - challenges$, - stories$, - ( - challenges, - stories, - ) => ({ challenges, stories }) - ) - .subscribe( - ({ challenges, stories }) => { - res.header('Content-Type', 'application/xml'); - res.render('resources/sitemap', { - appUrl, - now, - challenges, - stories - }); - }, - next - ); - } - router.get('/sitemap.xml', sitemap); - app.use(router); -}