Adding a minimal error system

This commit is contained in:
Nikola Bjelo committed 2018-10-27 18:19:55 +02:00
1 parent 959f9668e6
commit 481f64f1fe
14 files changed
+64 -5

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
export class AuthentificationError extends Error {
code = 401
message = 'You have to be authentificated to ' + ( this.message || "perform this action")
}
+1 -1
View File
@@ -6,7 +6,7 @@ import graphqlHTTP from 'express-graphql'
import expressPlayground from 'graphql-playground-middleware-express'
import schema from './schema'
const Sentry = require('@sentry/node')
import * as Sentry from '@sentry/node'
// Initialise express
const app = express()
+6 -1
View File
@@ -3,6 +3,7 @@ import {
GraphQLID,
GraphQLInt
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
@@ -13,8 +14,12 @@ const args = {
}
const resolve = (parent, { eventDesignator, rank, amount }, context) => {
const hostId = context.userId
if (!hostId) {
throw new AuthentificationError()
}
return new Promise((resolve, reject) => {
Event.findOne({ designator: eventDesignator, hostId: context.userId }).exec((err, event) => {
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
if (err || !event) {
reject(err)
} else {
+6 -1
View File
@@ -3,6 +3,7 @@ import {
GraphQLID,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
@@ -13,8 +14,12 @@ const args = {
}
const resolve = (parent, { eventDesignator, title, description }, context) => {
const hostId = context.userId
if (!hostId) {
throw new AuthentificationError()
}
return new Promise((resolve, reject) => {
Event.findOne({ designator: eventDesignator, hostId: context.userId }).exec((err, event) => {
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
if (err || !event) {
reject(err)
} else {
@@ -2,6 +2,7 @@ import {
GraphQLNonNull,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { EventType } from '../types'
import { Event, Formula } from '../../models'
@@ -12,6 +13,9 @@ const args = {
const resolve = (parent, { name, eventDesignator }, context) => {
const ownerId = context.userId
if (!ownerId) {
throw new AuthentificationError()
}
let newFormula = new Formula({ name, ownerId })
return new Promise((resolve, reject) => {
Event.findOne({ designator: eventDesignator, hostId: ownerId }).exec((err, event) => {
@@ -2,6 +2,7 @@ import {
GraphQLNonNull,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { EventType } from '../types'
import { Event, Plotter } from '../../models'
@@ -15,6 +16,9 @@ const args = {
const resolve = (parent, { name, host, repo, moduleName, eventDesignator }, context) => {
const ownerId = context.userId
if (!ownerId) {
throw new AuthentificationError()
}
let newPlotter = new Plotter({ name, host, repo, moduleName, ownerId })
return new Promise((resolve, reject) => {
Event.findOne({ designator: eventDesignator, hostId: ownerId }).exec((err, event) => {
@@ -2,6 +2,7 @@ import {
GraphQLNonNull,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { FormulaType } from '../types'
import { Formula } from '../../models'
@@ -11,6 +12,9 @@ const args = {
const resolve = (parent, { name }, context) => {
const ownerId = context.userId
if (!ownerId) {
throw new AuthentificationError()
}
let newFormula = new Formula({ name, ownerId })
return new Promise((resolve, reject) => {
newFormula.save((err) => {
@@ -2,6 +2,7 @@ import {
GraphQLNonNull,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { PlotterType } from '../types'
import { Plotter } from '../../models'
@@ -14,6 +15,9 @@ const args = {
const resolve = (parent, { name, host, repo, moduleName }, context) => {
const ownerId = context.userId
if (!ownerId) {
throw new AuthentificationError()
}
let newPlotter = new Plotter({ name, host, repo, moduleName, ownerId })
return new Promise((resolve, reject) => {
newPlotter.save((err) => {
+6 -1
View File
@@ -4,6 +4,7 @@ import {
GraphQLInt,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
@@ -18,8 +19,12 @@ const args = {
}
const resolve = (parent, { designator, name, description, startDatetime, finishDatetime, formulaId, plotterId }, context) => {
const hostId = context.userId
if (!hostId) {
throw new AuthentificationError()
}
return new Promise((resolve, reject) => {
Event.findOne({ designator, hostId: context.userId }).exec((err, event) => {
Event.findOne({ designator, hostId }).exec((err, event) => {
if (err || !event) {
reject(err)
} else {
@@ -3,6 +3,7 @@ import {
GraphQLID,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
@@ -14,6 +15,10 @@ const args = {
}
const resolve = (parent, { eventDesignator, teamId, botId, releaseId }, context) => {
const hostId = context.userId
if (!hostId) {
throw new AuthentificationError()
}
return new Promise((resolve, reject) => {
Event.findOne({ designator: eventDesignator }).exec((err, event) => {
if (err) reject(err)
+6 -1
View File
@@ -3,6 +3,7 @@ import {
GraphQLID,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
@@ -14,8 +15,12 @@ const args = {
}
const resolve = (parent, { eventDesignator, title, newtitle, description }, context) => {
const hostId = context.userId
if (!hostId) {
throw new AuthentificationError()
}
return new Promise((resolve, reject) => {
Event.findOne({ designator: eventDesignator, hostId: context.userId }).exec((err, event) => {
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
if (err || !event) {
reject(err)
} else {
+4
View File
@@ -3,6 +3,7 @@ import {
GraphQLInt,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
import { slugify } from '../../utils/functions'
@@ -16,6 +17,9 @@ const args = {
const resolve = (parent, { name, description, startDatetime, finishDatetime }, context) => {
const hostId = context.userId
if (!hostId) {
throw new AuthentificationError()
}
let newEvent = new Event({
hostId,
name,
@@ -3,6 +3,7 @@ import {
GraphQLID,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
@@ -14,6 +15,10 @@ const args = {
}
const resolve = (parent, { designator, teamId, botId, releaseId }, context) => {
const hostId = context.userId
if (!hostId) {
throw new AuthentificationError()
}
return new Promise((resolve, reject) => {
Event.findOne({ designator }).exec((err, event) => {
if (err) reject(err)
@@ -3,6 +3,7 @@ import {
GraphQLID,
GraphQLInt
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { isBetween } from '../../utils/functions'
import { EventType } from '../types'
import { Event } from '../../models'
@@ -14,6 +15,10 @@ const args = {
}
const resolve = (parent, { eventDesignator, fromPosition, toPosition }, context) => {
const hostId = context.userId
if (!hostId) {
throw new AuthentificationError()
}
return new Promise((resolve, reject) => {
Event.findOne({ designator: eventDesignator, hostId: context.userId }).exec((err, event) => {
if (err || !event) {