Uploading minimal boilerplate
This commit is contained in:
1 parent
8516cac965
commit
5652cb9b6d
42 files changed
+8144
-1
No files matched your search
@@ -0,0 +1,9 @@
|
||||
PRESHARED_GATEWAY_KEY=SECRET_STUFF
|
||||
|
||||
PORT=3000
|
||||
DB_USERNAME=example_name
|
||||
DB_PASSWORD=example_password
|
||||
DB_DOMAIN=example.com:1234/example_name
|
||||
|
||||
|
||||
GATEWAY_ENDPOINT=https://app-api.advancedalgos.net/graphql/
|
||||
@@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
parser: 'babel-eslint',
|
||||
extends: 'airbnb-base',
|
||||
rules: {
|
||||
'max-len': ['error', 140, 2],
|
||||
'no-underscore-dangle': 'off',
|
||||
'no-param-reassign': 'off',
|
||||
}
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# Build folder js files
|
||||
build/
|
||||
dist/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
|
||||
#Mac specific files
|
||||
.DS_Store
|
||||
@@ -0,0 +1,46 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team using the online form in the contacts page of the superalgos.org website. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
@@ -0,0 +1,45 @@
|
||||
# Contributing
|
||||
|
||||
We are thrilled you are interested in contributing to this repository. Your help may be essential to the project's success and we want you in!
|
||||
|
||||
Superalgos is a collective project, currently at a very early stage. Although this repository is not open source software yet, we do welcome contributions from the community.
|
||||
|
||||
Contributions are deemed _voluntary work_. There might be incentives in place for certain kinds of contributions. Contact us for more information in this regard.
|
||||
|
||||
In any case, contributors agree to provide an express grant of patent rights for their contributions. Submitting Pull Requests to this repository represents an express agreement with the terms of our Balanced Contributor Intellectual Property Agreement. This agreement is a direct implementation of GitHub's [Balanced Employee Intellectual Property Agreement 1.0.1](https://github.com/github/balanced-employee-ip-agreement/blob/master/Balanced_Employee_IP_Agreement.md).
|
||||
|
||||
# Balanced Contributor Intellectual Property Agreement 1.0.1
|
||||
|
||||
This BALANCED CONTRIBUTOR INTELLECTUAL PROPERTY AGREEMENT is between person or team submitting Pull Requests to this repository and Superalgos.org ("Project").
|
||||
|
||||
**What is this?** This is the Project's Intellectual Property Agreement ("Agreement"). If you've worked in the technology space before, there's a good chance that you've run across one or more of these in the past. This document is the official, entire and exclusive agreement on what intellectual property ("IP") is yours, and what belongs to the Project.
|
||||
|
||||
**Why is this?** The Project needs to be clear on what IP it owns and has rights to. Its customers, contributors, and investors depend on the Project having the legal rights to the products and services it is providing so that the Project can continue operating and doing business.
|
||||
|
||||
The Project also believes that it's important to be clear on what it doesn't own. The Project doesn't want you looking over your shoulder every time you work on something personal or worrying that the Project will someday seize your open source non-lethal mousetrap simulation software. In other words, the Project isn't interested in appropriating your personal projects.
|
||||
|
||||
**Read this.** Please read this document and be sure you understand it before you submit any Pull Requests. Due to legal risk and corporate obligations, the Project cannot, by and large, negotiate its terms. If you feel you have a particular circumstance that keeps you from signing, please let the Project's legal department ("Legal") know. And, of course, you're always free and encouraged to get your own legal counsel to explain anything you're not clear on.
|
||||
|
||||
Cool? Then, by submitting your first Pull Request, and as a condition of your contribution, you agree to the following:
|
||||
|
||||
1. **What the Project owns.** The Project owns any IP ("Project IP") that you create, or help create _as its contributor_, but only if it meets one or more of these additional conditions: The IP was (i) related to an existing or prospective Project product or service at the time you developed, invented, or created it, (ii) developed for use by the Project, or (iii) developed or promoted with existing Project IP or with the Project's endorsement. You hereby grant and assign, and will grant and assign, to the Project all rights and interests in all Project IP.
|
||||
|
||||
"Project IP" includes concepts, designs, developments, discoveries, ideas, improvements, inventions, trade secrets, trademarks, and works of authorship.
|
||||
|
||||
2. **What the Project doesn't own.** If you create IP that doesn't fit into one of the categories listed above, the Project doesn't own it. In other words, the Project doesn't own concepts, designs, developments, discoveries, ideas, improvements, inventions, trade secrets, trademarks, or works of authorship that you develop, invent, or create that do not meet any of the conditions in Section 1.
|
||||
|
||||
3. **Contribution of your IP to Project projects.** If you include your own IP – such as IP you created prior to working for the Project – into a Project product or service, it's still yours, of course, but you grant the Project a non-exclusive, irrevocable, fully paid-up, royalty-free, perpetual, sublicensable, transferable, worldwide license to use it without restriction in any way or implementation, in modified form, or as is, by itself, or incorporated into another product or service ("License"). If you include your name in any project over which the Project would have rights under this Agreement, such as in a copyright notice or a comment in code or documentation, then the License covers the rights associated with that use of your name as well.
|
||||
|
||||
4. **Your contributions to non-Project projects.** The Project recognizes that you may be engaged in work that requires you to submit IP to entities other than the Project, such as open source projects used by the Project. Please make sure that Legal is aware of what you're working on so that Legal can help with any licensing issues. If any project asks you to sign a contribution agreement, you should check with Legal before doing so. These agreements may be legally binding on the Project and so should be run through Legal first.
|
||||
|
||||
5. **Voluntary Works** All Project IP that you are involved with or create as part of your work for the Project is voluntary work which does not require compensation. There might be incentives in place for certain kinds of contributions. Feel free to contact the Project to learn more.
|
||||
|
||||
6. **No conflicts.** You agree that you don't have any outstanding agreements or obligations that conflict with those in this Agreement, and that you won't enter into conflicting agreements in the future.
|
||||
|
||||
7. **IP protection.** The Project might someday need to show the work that went into the development of IP that it uses or has used, or to make government filings to establish that it owns the IP or has rights over it. To help in those situations, you agree not to destroy any records you maintain relating to the development of any Project IP or IP under License (together, "All IP"), and, if the Project asks, to provide those records to the Project. You agree to help the Project secure and defend its rights in All IP. For your help the Project will compensate you at a reasonable rate. If the Project is unable to secure your help, you authorize the Project to act on your behalf (as your agent and attorney-in-fact) in securing all rights related to All IP.
|
||||
|
||||
8. **Confidentiality.** As an contributor or contractor of the Project, you will have access to sensitive confidential information that is important to the Project's business. You are responsible for keeping this information confidential, including after you end your work for the Project.
|
||||
|
||||
"Confidential Information" includes non-public technical details about our products or services, financial information, business strategies and forecasts, customer data, or any other information, data or know-how that is valuable to the Project because it is not publicly known.
|
||||
|
||||
The Project's Confidential Information is sensitive and we expect that you'll treat it as such. You agree to only use the Project's Confidential Information for the purpose of performing your contribution and for the benefit of the Project. You will do your best to keep Confidential Information secret. If you are not sure if something is Confidential Information, you should assume that it is, until you can confirm otherwise.
|
||||
@@ -0,0 +1,39 @@
|
||||
COPYRIGHT NOTICE
|
||||
|
||||
© Copyright 2018 Superalgos.org
|
||||
|
||||
|
||||
LICENSE NOTICE
|
||||
|
||||
Superalgos is a collaborative project currently at a very early stage. Because certain aspects of
|
||||
the project are still not clearly defined, we have chosen to --temporarily-- grant a restrictive
|
||||
license for the use of this repository, until those aspects are clarified and a proper open source
|
||||
license can be granted.
|
||||
|
||||
Superalgos.org is publishing the code of this software for several reasons. However, it shall not be considered free software yet. Superalgos is a collaborative project in the crypto space and this
|
||||
software is still proprietary software.
|
||||
|
||||
The reasons for opening up the code of this software at this stage are the following:
|
||||
|
||||
* We believe that transparency is paramount to achieving our goals, so we want everyone to
|
||||
be able to understand what this software does and how. Opening up the code of this software
|
||||
allows anyone to take a close look.
|
||||
|
||||
* We welcome contributions from the community. Contributions are regarded as voluntary work.
|
||||
There may be incentives in place for certain kinds of contributions. Contact us to learn more.
|
||||
Contributors agree to provide an express grant of patent rights for their contributions.
|
||||
|
||||
|
||||
LICENSE WORDING
|
||||
|
||||
Superalgos.org grants a limited license for the following uses:
|
||||
|
||||
1. CODE REVIEW AND AUDITS. You are granted permission to clone this repository to analyze,
|
||||
review or audit the code.
|
||||
|
||||
2. COLLABORATING WITH Superalgos.org. You are granted permission to fork this repository
|
||||
with the sole purpose of correcting bugs and developing functionality in agreement with
|
||||
Superalgos.org. By contributing to this repository you explicitely agree to the terms
|
||||
detailed in CONTRIBUTING.MD.
|
||||
|
||||
PLEASE SEE CONTRIBUTING.MD FOR MORE DETAILS ON THE IMPLICATIONS SURROUNDING YOUR CONTRIBUTIONS TO THIS REPOSITORY.
|
||||
@@ -1 +1,20 @@
|
||||
node_mongoose
|
||||
This is a draft of the boilerplate we'll use for backends using mongoose and node.
|
||||
|
||||
The following files are there as examples, you have to change them with your own :
|
||||
**/index.js files should be adapted for your file structure
|
||||
|
||||
./src/enums/EventState.js
|
||||
|
||||
./src/models/event.js
|
||||
./src/models/plotter.js
|
||||
./src/models/formula.js
|
||||
If you have relations between items, don't forget the "this.populate" statement (check ./src/models/events.js)
|
||||
|
||||
./src/schema/mutations/ChangeEventState.js => left there so you can see how to make mutation that take "normal arguments"
|
||||
./src/schema/mutations/CreateEvent.js => left there so you can see how to make mutation that take "custom input types" as arguments
|
||||
./src/schema/mutations/EditParticipant.js => left so you can see how to use axios to call another of our services if needed
|
||||
|
||||
./src/schema/queries/Events.js => minimal query
|
||||
./src/schema/queries/EventsByHost.js => query with an argument
|
||||
|
||||
./src/schema/types/** => a few examples where left there so you can check them out, globally => first define your "return types" who should be very similar to your models. Then create you "input types" who should be used as much as possible if the input is a complexe object. It will help in the future when adding features as pageability, traits etc...
|
||||
Generated
+7165
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "events-server",
|
||||
"version": "0.1.0",
|
||||
"description": "Advanced Algos Event backend API",
|
||||
"author": "",
|
||||
"license": "",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon --exec babel-node --presets env,stage-2 src/index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"/src/errors/index.js"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"eslint": "^5.8.0",
|
||||
"eslint-config-airbnb-base": "^13.1.0",
|
||||
"eslint-plugin-import": "^2.14.0",
|
||||
"nodemon": "^1.18.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"apollo-server-express": "^2.1.0",
|
||||
"axios": "^0.18.0",
|
||||
"dotenv": "^6.0.0",
|
||||
"express": "^4.16.3",
|
||||
"graphql": "^0.13.2",
|
||||
"mongoose": "^5.3.4"
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import 'dotenv/config';
|
||||
import express from 'express';
|
||||
import { ApolloServer } from 'apollo-server-express';
|
||||
import schema from './schema';
|
||||
import wrongPreshared from './errors/notAllowed.json';
|
||||
|
||||
const app = express();
|
||||
|
||||
app.post('/graphql', (req, res, next) => {
|
||||
if (req.headers.preshared === process.env.PRESHARED_GATEWAY_KEY) {
|
||||
next();
|
||||
} else {
|
||||
res.send(wrongPreshared);
|
||||
}
|
||||
});
|
||||
|
||||
// Starting the graphql server
|
||||
const server = new ApolloServer({
|
||||
schema,
|
||||
playground: {
|
||||
settings: {
|
||||
'editor.theme': 'dark',
|
||||
'editor.cursorShape': 'line',
|
||||
},
|
||||
},
|
||||
context: ({ req }) => ({
|
||||
userId: req.headers.userid,
|
||||
authorization: req.headers.authorization,
|
||||
}),
|
||||
formatError: error => ({
|
||||
code: error.extensions.exception.code,
|
||||
message: error.message,
|
||||
path: error.path,
|
||||
}),
|
||||
introspection: true,
|
||||
});
|
||||
|
||||
server.applyMiddleware({
|
||||
app,
|
||||
cors: true,
|
||||
});
|
||||
|
||||
export default app;
|
||||
@@ -0,0 +1,11 @@
|
||||
import 'dotenv/config';
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
mongoose.connect(`mongodb://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@${process.env.DB_DOMAIN}`, { useNewUrlParser: true });
|
||||
mongoose.set('useCreateIndex', true);
|
||||
mongoose.set('useFindAndModify', false);
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
const db = mongoose.connection;
|
||||
|
||||
export default db;
|
||||
@@ -0,0 +1,19 @@
|
||||
export const UNPUBLISHED = 'UNPUBLISHED';
|
||||
export const PUBLISHED = 'PUBLISHED';
|
||||
export const CANCELLED = 'CANCELLED';
|
||||
export const RUNNING = 'RUNNING';
|
||||
export const INTERRUPTED = 'INTERRUPTED';
|
||||
export const FINISHED = 'FINISHED';
|
||||
export const ARCHIVED = 'ARCHIVED';
|
||||
|
||||
export const EventStateEnum = [
|
||||
UNPUBLISHED,
|
||||
PUBLISHED,
|
||||
CANCELLED,
|
||||
RUNNING,
|
||||
INTERRUPTED,
|
||||
FINISHED,
|
||||
ARCHIVED,
|
||||
];
|
||||
|
||||
export default EventStateEnum;
|
||||
@@ -0,0 +1,45 @@
|
||||
import * as Sentry from '@sentry/node';
|
||||
|
||||
class ClientError extends Error {
|
||||
constructor(args) {
|
||||
super(args);
|
||||
Sentry.configureScope((scope) => {
|
||||
scope.setLevel('debug');
|
||||
});
|
||||
Sentry.captureException(this);
|
||||
}
|
||||
}
|
||||
|
||||
class ServerError extends Error {
|
||||
constructor(args) {
|
||||
super(args);
|
||||
Sentry.configureScope((scope) => {
|
||||
scope.setLevel('error');
|
||||
});
|
||||
Sentry.captureException(this);
|
||||
}
|
||||
}
|
||||
|
||||
export class AuthentificationError extends ClientError {
|
||||
code = 401
|
||||
|
||||
message = 'Autentification not found, you have to be authentificated to perform this action'
|
||||
}
|
||||
|
||||
export class DatabaseError extends ClientError {
|
||||
code = 404
|
||||
|
||||
message = `Ressource not found : ${this.message}`
|
||||
}
|
||||
|
||||
export class WrongArgumentsError extends ClientError {
|
||||
code = 400
|
||||
|
||||
message = `Wrong arguments : ${this.message}`
|
||||
}
|
||||
|
||||
export class ServiceUnavailableError extends ServerError {
|
||||
code = 503
|
||||
|
||||
message = `At least one service is unresponding ${this.message}`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": 401,
|
||||
"message": "Wait, you're not supposed to be here, go through the gate as everyone else"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/* eslint-disable no-console */
|
||||
import db from './db';
|
||||
import app from './app';
|
||||
|
||||
db.on('error', (err) => {
|
||||
console.log(err);
|
||||
});
|
||||
db.once('open', () => {
|
||||
console.log('Connected to the DB.');
|
||||
});
|
||||
|
||||
app.listen(process.env.PORT, () => {
|
||||
console.log(`Listening on port ${process.env.PORT}`);
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
import mongoose, { Schema } from 'mongoose';
|
||||
import Plotter from './plotter';
|
||||
import Formula from './formula';
|
||||
import {
|
||||
UNPUBLISHED,
|
||||
EventStateEnum,
|
||||
} from '../enums/EventState';
|
||||
|
||||
const { ObjectId } = Schema.Types;
|
||||
|
||||
const eventSchema = new Schema({
|
||||
state: {
|
||||
type: String,
|
||||
enum: EventStateEnum,
|
||||
default: UNPUBLISHED,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
hostId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
formulaId: {
|
||||
type: ObjectId,
|
||||
ref: Formula.modelName,
|
||||
},
|
||||
plotterId: {
|
||||
type: ObjectId,
|
||||
ref: Plotter.modelName,
|
||||
},
|
||||
prizes: [{
|
||||
rank: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
subPrize: [{
|
||||
condition: String,
|
||||
}],
|
||||
}],
|
||||
});
|
||||
|
||||
eventSchema.pre('find', function populate() {
|
||||
this.populate('formulaId').populate('plotterId');
|
||||
});
|
||||
eventSchema.post('save', (doc, next) => {
|
||||
doc.populate('formulaId').populate('plotterId').execPopulate().then(() => {
|
||||
next();
|
||||
});
|
||||
});
|
||||
eventSchema.post('findOneAndUpdate', (doc, next) => {
|
||||
doc.populate('formulaId').populate('plotterId').execPopulate().then(() => {
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
const Event = mongoose.model('Event', eventSchema);
|
||||
|
||||
export default Event;
|
||||
@@ -0,0 +1,12 @@
|
||||
import mongoose, { Schema } from 'mongoose';
|
||||
|
||||
const formulaSchema = new Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
const Formula = mongoose.model('Formula', formulaSchema);
|
||||
|
||||
export default Formula;
|
||||
@@ -0,0 +1,9 @@
|
||||
import Plotter from './plotter';
|
||||
import Event from './event';
|
||||
import Formula from './formula';
|
||||
|
||||
export {
|
||||
Event,
|
||||
Plotter,
|
||||
Formula,
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
import mongoose, { Schema } from 'mongoose';
|
||||
|
||||
const plotterSchema = new Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
const Plotter = mongoose.model('Plotter', plotterSchema);
|
||||
|
||||
export default Plotter;
|
||||
@@ -0,0 +1,13 @@
|
||||
import {
|
||||
GraphQLSchema,
|
||||
} from 'graphql';
|
||||
|
||||
import Mutation from './mutations';
|
||||
import RootQuery from './queries';
|
||||
|
||||
const Schema = new GraphQLSchema({
|
||||
query: RootQuery,
|
||||
mutation: Mutation,
|
||||
});
|
||||
|
||||
export default Schema;
|
||||
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import EventStateEnum from '../types/enum/EventState';
|
||||
|
||||
const args = {
|
||||
eventId: { type: new GraphQLNonNull(GraphQLID) },
|
||||
state: { type: EventStateEnum },
|
||||
};
|
||||
|
||||
const resolve = (parent, { eventId: _id, state }, { userId: hostId }) => {
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOneAndUpdate({ _id, hostId }, { state }, { new: true }, (err, modifiedEvent) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
res(modifiedEvent);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
changeEventState: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -0,0 +1,37 @@
|
||||
import { AuthentificationError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { EventInputType } from '../types/input';
|
||||
|
||||
export const args = {
|
||||
event: { type: EventInputType },
|
||||
};
|
||||
|
||||
const resolve = (parent, { event }, { userId: hostId }) => {
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
|
||||
event.hostId = hostId;
|
||||
const newEvent = new Event(event);
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
newEvent.save((err) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
res(newEvent);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
createEvent: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -0,0 +1,81 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
} from 'graphql';
|
||||
import axios from 'axios';
|
||||
import {
|
||||
AuthentificationError,
|
||||
WrongArgumentsError,
|
||||
ServiceUnavailableError,
|
||||
} from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
|
||||
const args = {
|
||||
eventId: { type: new GraphQLNonNull(GraphQLID) },
|
||||
};
|
||||
|
||||
const resolve = (parent,
|
||||
{ eventId: _id, participant: { teamId, botId, releaseId } },
|
||||
{ userId, authorization }) => {
|
||||
if (!userId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
return new Promise((res, rej) => {
|
||||
axios({
|
||||
url: process.env.GATEWAY_ENDPOINT,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
{
|
||||
teams_TeamsByRole{
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
headers: { authorization },
|
||||
}).then(
|
||||
(result) => {
|
||||
if (!result.data.data.teamsByRole.some(team => team.id === teamId)) {
|
||||
rej(new WrongArgumentsError('You are not eligible to edit this team'));
|
||||
return;
|
||||
}
|
||||
Event.findOne({ _id }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
const participantIndex = event.participant
|
||||
.findIndex(participant => participant.teamId === teamId);
|
||||
|
||||
event.participants[participantIndex].botId = botId
|
||||
|| event.participants[participantIndex].botId;
|
||||
event.participants[participantIndex].releaseId = releaseId
|
||||
|| event.participants[participantIndex].releaseId;
|
||||
|
||||
event.save((error) => {
|
||||
if (error) {
|
||||
rej(error);
|
||||
return;
|
||||
}
|
||||
res(event);
|
||||
});
|
||||
});
|
||||
},
|
||||
(error) => {
|
||||
rej(new ServiceUnavailableError(error));
|
||||
},
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
editParticipant: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -0,0 +1,16 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
} from 'graphql';
|
||||
|
||||
import CreateEventMutation from './CreateEvent';
|
||||
import ChangeEventStateMutation from './ChangeEventState';
|
||||
|
||||
const Mutation = new GraphQLObjectType({
|
||||
name: 'Mutation',
|
||||
fields: Object.assign(
|
||||
CreateEventMutation,
|
||||
ChangeEventStateMutation,
|
||||
),
|
||||
});
|
||||
|
||||
export default Mutation;
|
||||
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
GraphQLInt,
|
||||
GraphQLList,
|
||||
} from 'graphql';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { UNPUBLISHED, ARCHIVED } from '../../enums/EventState';
|
||||
|
||||
const args = {
|
||||
minDate: { type: GraphQLInt },
|
||||
maxDate: { type: GraphQLInt },
|
||||
};
|
||||
|
||||
const resolve = (parent, { minDate, maxDate }) => Event.find(
|
||||
Object.assign(
|
||||
{ state: { $nin: [UNPUBLISHED, ARCHIVED] } },
|
||||
minDate || maxDate
|
||||
? {
|
||||
startDatetime:
|
||||
Object.assign(
|
||||
minDate ? { $gte: minDate } : {},
|
||||
maxDate ? { $lte: maxDate } : {},
|
||||
),
|
||||
}
|
||||
: {},
|
||||
),
|
||||
);
|
||||
|
||||
const query = {
|
||||
events: {
|
||||
type: new GraphQLList(EventType),
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default query;
|
||||
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
GraphQLInt,
|
||||
GraphQLList,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { UNPUBLISHED, ARCHIVED } from '../../enums/EventState';
|
||||
|
||||
const args = {
|
||||
hostId: { type: GraphQLString },
|
||||
minDate: { type: GraphQLInt },
|
||||
maxDate: { type: GraphQLInt },
|
||||
};
|
||||
|
||||
const resolve = (parent, { hostId, minDate, maxDate }, context) => Event.find(
|
||||
Object.assign(
|
||||
hostId ? { hostId, state: { $nin: [UNPUBLISHED, ARCHIVED] } } : { hostId: context.userId },
|
||||
minDate || maxDate
|
||||
? {
|
||||
startDatetime:
|
||||
Object.assign(
|
||||
minDate ? { $gte: minDate } : {},
|
||||
maxDate ? { $lte: maxDate } : {},
|
||||
),
|
||||
}
|
||||
: {},
|
||||
),
|
||||
);
|
||||
|
||||
const query = {
|
||||
eventsByHost: {
|
||||
type: new GraphQLList(EventType),
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default query;
|
||||
@@ -0,0 +1,16 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
} from 'graphql';
|
||||
|
||||
import EventsQuery from './Events';
|
||||
import EventsByHostQuery from './EventsByHost';
|
||||
|
||||
const RootQuery = new GraphQLObjectType({
|
||||
name: 'RootQueryType',
|
||||
fields: Object.assign(
|
||||
EventsQuery,
|
||||
EventsByHostQuery,
|
||||
),
|
||||
});
|
||||
|
||||
export default RootQuery;
|
||||
@@ -0,0 +1,43 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList,
|
||||
GraphQLID,
|
||||
} from 'graphql';
|
||||
import {
|
||||
FormulaType,
|
||||
PlotterType,
|
||||
PrizeType,
|
||||
} from './index';
|
||||
import EventStateEnumType from './enum/EventState';
|
||||
|
||||
const EventType = new GraphQLObjectType({
|
||||
name: 'Event',
|
||||
description: 'Everything you need to know about an event',
|
||||
fields: () => ({
|
||||
id: { type: GraphQLID },
|
||||
state: { type: EventStateEnumType },
|
||||
name: { type: GraphQLString },
|
||||
hostId: { type: GraphQLString },
|
||||
formula: {
|
||||
type: FormulaType,
|
||||
resolve(parent) {
|
||||
return parent.formulaId;
|
||||
},
|
||||
},
|
||||
plotter: {
|
||||
type: PlotterType,
|
||||
resolve(parent) {
|
||||
return parent.plotterId;
|
||||
},
|
||||
},
|
||||
prizes: {
|
||||
type: new GraphQLList(PrizeType),
|
||||
resolve(parent) {
|
||||
return parent.prizes;
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
export default EventType;
|
||||
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
|
||||
const FormulaType = new GraphQLObjectType({
|
||||
name: 'Formula',
|
||||
description: 'For now it\'s simplay a named field',
|
||||
fields: () => ({
|
||||
id: { type: GraphQLString },
|
||||
name: { type: GraphQLString },
|
||||
}),
|
||||
});
|
||||
|
||||
export default FormulaType;
|
||||
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
|
||||
const PlotterType = new GraphQLObjectType({
|
||||
name: 'Plotter',
|
||||
description: 'Will soon change in order to use contained plotter objects',
|
||||
fields: () => ({
|
||||
id: { type: GraphQLString },
|
||||
name: { type: GraphQLString },
|
||||
}),
|
||||
});
|
||||
|
||||
export default PlotterType;
|
||||
@@ -0,0 +1,23 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLList,
|
||||
GraphQLString,
|
||||
GraphQLNonNull,
|
||||
} from 'graphql';
|
||||
import { SubPrizeType } from './index';
|
||||
|
||||
const PrizeType = new GraphQLObjectType({
|
||||
name: 'Prize',
|
||||
description: 'Prize, by default in algos',
|
||||
fields: () => ({
|
||||
rank: { type: new GraphQLNonNull(GraphQLString) },
|
||||
subPrize: {
|
||||
type: new GraphQLList(SubPrizeType),
|
||||
resolve(parent) {
|
||||
return parent.subPrize;
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
export default PrizeType;
|
||||
@@ -0,0 +1,14 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
|
||||
const SubPrizeType = new GraphQLObjectType({
|
||||
name: 'SubPrize',
|
||||
description: 'Prize',
|
||||
fields: () => ({
|
||||
condition: { type: GraphQLString },
|
||||
}),
|
||||
});
|
||||
|
||||
export default SubPrizeType;
|
||||
@@ -0,0 +1,19 @@
|
||||
import {
|
||||
GraphQLEnumType,
|
||||
} from 'graphql';
|
||||
|
||||
import { EventStateEnum } from '../../../enums/EventState';
|
||||
|
||||
const values = {};
|
||||
EventStateEnum.forEach((EventState) => {
|
||||
values[EventState] = { value: EventState };
|
||||
});
|
||||
|
||||
const EventStateEnumType = new GraphQLEnumType({
|
||||
name: 'EventStateEnum',
|
||||
values,
|
||||
});
|
||||
|
||||
export {
|
||||
EventStateEnumType as default,
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import PlotterType from './Plotter';
|
||||
import SubPrizeType from './SubPrize';
|
||||
import PrizeType from './Prize';
|
||||
import FormulaType from './Formula';
|
||||
import EventType from './Event';
|
||||
|
||||
export {
|
||||
PlotterType,
|
||||
SubPrizeType,
|
||||
PrizeType,
|
||||
FormulaType,
|
||||
EventType,
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import {
|
||||
GraphQLString,
|
||||
GraphQLInputObjectType,
|
||||
GraphQLList,
|
||||
} from 'graphql';
|
||||
import InputPrizeType from './Prize';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'EventInput',
|
||||
description: 'Payload for event input',
|
||||
fields: () => ({
|
||||
name: { type: GraphQLString },
|
||||
formulaId: { type: GraphQLString },
|
||||
plotterId: { type: GraphQLString },
|
||||
prizes: { type: new GraphQLList(InputPrizeType) },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
GraphQLInputObjectType,
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'FormulaInput',
|
||||
description: 'Payload for formula input',
|
||||
fields: () => ({
|
||||
name: { type: new GraphQLNonNull(GraphQLString) },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
GraphQLInputObjectType,
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'PlotterInput',
|
||||
description: 'Payload for plotter input',
|
||||
fields: () => ({
|
||||
name: { type: new GraphQLNonNull(GraphQLString) },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLList,
|
||||
GraphQLInt,
|
||||
GraphQLNonNull,
|
||||
} from 'graphql';
|
||||
import InputSubPrizeType from './SubPrize';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'PrizeInput',
|
||||
description: 'Payload for formula input',
|
||||
fields: () => ({
|
||||
rank: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
amount: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
subPrize: {
|
||||
type: new GraphQLList(InputSubPrizeType),
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,14 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'SubPrizeInput',
|
||||
description: 'Payload prize input',
|
||||
fields: () => ({
|
||||
condition: { type: GraphQLString },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,13 @@
|
||||
import PlotterInputType from './Plotter';
|
||||
import PrizeInputType from './Prize';
|
||||
import FormulaInputType from './Formula';
|
||||
import EventInputType from './Event';
|
||||
import SubPrizeInputType from './SubPrize';
|
||||
|
||||
export {
|
||||
PlotterInputType,
|
||||
PrizeInputType,
|
||||
FormulaInputType,
|
||||
EventInputType,
|
||||
SubPrizeInputType,
|
||||
};
|
||||
Whitespace-only changes.
Reference in new issue
Block a user