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

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

@ -335,10 +335,33 @@ export function resolver(req: any, res: any): any {
return new NotLoggedInGqlError();
}
},
async createEvent({name, dueDate, groupId}: {name: string, dueDate: Date, groupId: number}) {
async createEvent({name, dueDate, groupId}: {name: string, dueDate: string, groupId: number}) {
if (req.session.userId) {
const date = new Date(dueDate);
const group = await models.Group.findByPk(groupId);
const event = await group.$create<models.Event>("rEvents", {name, dueDate});
return group.$create<models.Event>("rEvent", {name, dueDate: date});
} else {
res.status(status.UNAUTHORIZED);
return new NotLoggedInGqlError();
}
},
async joinEvent({eventId}: {eventId: number}) {
if (req.session.userId) {
const event = await models.Event.findByPk(eventId);
const self = await models.User.findByPk(req.session.userId);
await event.$add("rParticipants", self);
return event;
} else {
res.status(status.UNAUTHORIZED);
return new NotLoggedInGqlError();
}
},
async leaveEvent({eventId}: {eventId: number}) {
if (req.session.userId) {
const event = await models.Event.findByPk(eventId);
const self = await models.User.findByPk(req.session.userId);
await event.$remove("rParticipants", self);
return event;
} else {
res.status(status.UNAUTHORIZED);
return new NotLoggedInGqlError();

@ -84,6 +84,15 @@ type Mutation {
"removes an admin from the group"
removeGroupAdmin(groupId: ID!, userId: ID!): Group
"Creates a new event with a epoch due date on a group."
createEvent(name: String, dueDate: String, groupId: ID!): Event
"Joins a event."
joinEvent(eventId: ID!): Event
"Leaves a event."
leaveEvent(eventId: ID!): Event
}
interface UserData {
@ -161,6 +170,9 @@ type Profile implements UserData {
"name of the User"
name: String!
"the email of the user"
email: String!
"returns the chatrooms the user joined."
chats(first: Int=10, offset: Int): [ChatRoom]
@ -301,6 +313,26 @@ type Group {
"the groups chat"
chat: ChatRoom
"the events of the group"
events: [Event!]!
}
type Event {
"ID of the event"
id: ID!
"Name of the event"
name: String!
"The date of the event."
dueDate: String!
"The group the event belongs to."
group: Group!
"The participants of the event."
participants: [User!]!
}
"represents the type of vote performed on a post"

@ -229,6 +229,7 @@ namespace dataaccess {
* @param members
*/
export async function createGroup(name: string, creator: number, members: number[]): Promise<models.Group> {
members = members || [];
return sequelize.transaction(async (t) => {
members.push(creator);
const groupChat = await createChat(...members);

Loading…
Cancel
Save