Merge branch 'julius-dev' of Software_Engineering_I/greenvironment-server into develop

pull/2/head
Trivernis 5 years ago committed by Gitea
commit d7af503d09

@ -49,6 +49,22 @@ export function resolver(req: any, res: any): any {
return new GraphQLError("No chatId given.");
}
},
async getGroup({groupId}: {groupId: number}) {
if (groupId) {
return models.Group.findByPk(groupId);
} else {
res.status(status.BAD_REQUEST);
return new GraphQLError("No group id given.");
}
},
async getRequest({requestId}: {requestId: number}) {
if (requestId) {
return models.Request.findByPk(requestId);
} else {
res.status(status.BAD_REQUEST);
return new GraphQLError("No requestId given.");
}
},
acceptCookies() {
req.session.cookiesAccepted = true;
return true;
@ -307,7 +323,6 @@ export function resolver(req: any, res: any): any {
res.status(status.FORBIDDEN);
return new GraphQLError("You are not allowed to remove a creator as an admin.");
}
try {
return await dataaccess
.changeGroupMembership(groupId, userId, dataaccess.MembershipChangeAction.DEOP);
@ -315,7 +330,15 @@ export function resolver(req: any, res: any): any {
res.status(status.BAD_REQUEST);
return err.graphqlError;
}
} else {
res.status(status.UNAUTHORIZED);
return new NotLoggedInGqlError();
}
},
async createEvent({name, dueDate, groupId}: {name: string, dueDate: Date, groupId: number}) {
if (req.session.userId) {
const group = await models.Group.findByPk(groupId);
const event = await group.$create<models.Event>("rEvents", {name, dueDate});
} else {
res.status(status.UNAUTHORIZED);
return new NotLoggedInGqlError();

@ -11,6 +11,12 @@ type Query {
"returns the chat object for a chat id"
getChat(chatId: ID!): ChatRoom
"return shte group object for its id"
getGroup(groupId: ID!): Group
"returns the request object for its id"
getRequest(requestId: ID!): Request
"find a post by the posted date or content"
findPost(first: Int, offset: Int, text: String!, postedDate: String): [Post]
@ -228,6 +234,10 @@ type Post {
"represents a request of any type"
type Request {
"Id of the request."
id: ID!
"Id of the user who sended the request"
sender: User!

@ -5,6 +5,7 @@ import {ChatNotFoundError} from "./errors/ChatNotFoundError";
import {EmailAlreadyRegisteredError} from "./errors/EmailAlreadyRegisteredError";
import {GroupNotFoundGqlError, NotLoggedInGqlError} from "./errors/graphqlErrors";
import {GroupNotFoundError} from "./errors/GroupNotFoundError";
import {InvalidLoginError} from "./errors/InvalidLoginError";
import {NoActionSpecifiedError} from "./errors/NoActionSpecifiedError";
import {UserNotFoundError} from "./errors/UserNotFoundError";
import globals from "./globals";
@ -75,9 +76,13 @@ namespace dataaccess {
const hash = crypto.createHash("sha512");
hash.update(password);
password = hash.digest("hex");
const user = await models.User.findOne({where: {email, password}});
const user = await models.User.findOne({where: {email}});
if (user) {
return user;
if (user.password === password) {
return user;
} else {
throw new InvalidLoginError(email);
}
} else {
throw new UserNotFoundError(email);
}

@ -0,0 +1,7 @@
import {BaseError} from "./BaseError";
export class InvalidLoginError extends BaseError {
constructor(email: (string)) {
super(`Invalid login data for ${email}.`);
}
}
Loading…
Cancel
Save