Get events by owner

This commit is contained in:
Amit Jakubowicz 2019-03-23 18:13:06 +01:00
parent 486acfebec
commit 5f142b691a
7 changed files with 133 additions and 34 deletions

View file

@ -27,7 +27,7 @@ export namespace GQL {
}
interface IEventsOnQueryArguments {
filter?: IEventsQueryFilter | null;
filter: IEventsQueryFilter;
}
interface IUser {
@ -40,13 +40,14 @@ export namespace GQL {
interface IEventsQueryFilter {
limit?: number | null;
owner?: string | null;
}
interface ICalendarEvent {
__typename: 'CalendarEvent';
id: string;
owner: IUser;
info: Array<IEventInformation | null>;
info: IEventInformation;
time: IEventTime;
status: any;
contact: Array<IEventContactPerson>;
@ -55,7 +56,6 @@ export namespace GQL {
interface IEventInformation {
__typename: 'EventInformation';
language: string;
title: string;
description: string | null;
}
@ -97,7 +97,7 @@ export namespace GQL {
interface IMutation {
__typename: 'Mutation';
signup: boolean;
signup: Array<IError | null> | null;
signin: IUserSession;
requestInvite: boolean;
createEvent: ICalendarEvent | null;
@ -126,6 +126,12 @@ export namespace GQL {
name: string;
}
interface IError {
__typename: 'Error';
path: string;
message: string;
}
interface ISigninInput {
hash: string;
}

View file

@ -10,7 +10,7 @@ import {SessionInvite} from "./Session.entity"
@Entity("app_user")
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
@PrimaryGeneratedColumn("uuid")
id: string
@Column()

View file

@ -6,7 +6,7 @@ import {
OneToMany,
OneToOne,
ManyToOne,
CreateDateColumn
CreateDateColumn, JoinColumn
} from "typeorm"
import {User} from "../Auth/User.entity"
@ -63,6 +63,7 @@ export class Event extends BaseEntity {
id: number
@ManyToOne(type => User, user => user.events)
@JoinColumn()
owner: User
@Column(type => EventInformation)

View file

@ -12,6 +12,62 @@ let testClient
let connection: Connection = null
let sendEmailMock
const createKiteflyingEvent = async () => {
const owner = new User()
owner.name = "Kite Flyer"
owner.username = 'kites_are_us'
owner.email = "info@kites.com"
await owner.save()
const session = new Session()
session.user = owner
session.hash = 'kite_owners_auth_hash'
session.isValid = true
await session.save()
const event = new Event()
event.owner = owner
event.info = {
title: "Kite Flying Test Event",
description: "Description for test event starting at 3pm"
}
event.time = {
timeZone: 'Europe/Madrid',
start: new Date("2019-10-10T13:00Z"),
end: new Date("2019-10-10T14:00Z"),
}
event.status = "Scheduled"
return await event.save()
}
const createKinttingEvent = async () => {
const owner = new User()
owner.name = "Knitty User"
owner.username = 'kintting_is_fun'
owner.email = "info@knitting.com"
await owner.save()
const session = new Session()
session.user = owner
session.hash = 'knitty_owners_auth_hash'
session.isValid = true
await session.save()
const event = new Event()
event.owner = owner
event.info = {
title: "Knitting Test Event",
description: "Description for test event starting at 3pm"
}
event.time = {
timeZone: 'Europe/Madrid',
start: new Date("2019-10-10T14:00Z"),
end: new Date("2019-10-10T15:00Z"),
}
event.status = "Scheduled"
return await event.save()
}
describe('Events resolver', () => {
beforeAll(async () => {
return connection = await createConnection({
@ -33,34 +89,9 @@ describe('Events resolver', () => {
await connection.close()
})
it('Create Event', async (done) => {
const owner = new User()
owner.name = "Kite Flyer"
owner.username = 'kites_are_us'
owner.email = "info@kites.com"
await owner.save()
const session = new Session()
session.user = owner
session.hash = 'kite_owners_auth_hash'
session.isValid = true
await session.save()
const event = new Event()
event.owner = owner
event.info = {
title: "Test event",
description: "Description for test event starting at 3pm"
}
event.time = {
timeZone: 'Europe/Madrid',
start: new Date("2019-10-10T13:00Z"),
end: new Date("2019-10-10T14:00Z"),
}
event.status = "Scheduled"
await event.save()
it('Create Kiteflying Event', async (done) => {
await createKiteflyingEvent()
expect(await Event.count()).toEqual(1)
const res = await testClient.query({
query: gql`
query {
@ -85,4 +116,37 @@ describe('Events resolver', () => {
expect(res.data.events).toHaveLength(1)
done()
})
it('Create knitting event', async (done) => {
await createKinttingEvent()
const kinttingUser = await User.findOne({username: "kintting_is_fun"})
console.log('kinttingUser', kinttingUser.id)
const res = await testClient.query({
query: gql`
query GetEvent($ownerId: ID!){
events(filter: {limit: 10, owner: $ownerId}) {
id
info {
title
description
}
status
time {
timeZone
start
end
}
}
}
`,
variables: {
ownerId: kinttingUser.id
}
})
expect(res.errors).toBeUndefined()
expect(res.data).toBeDefined()
expect(res.data.events).toHaveLength(1)
expect(res.data.events[0].info.title).toEqual("Knitting Test Event")
done()
})
})

View file

@ -6,7 +6,8 @@ const resolvers: ResolverMap = {
Query: {
events: async (_, req: GQL.IEventsOnQueryArguments, context, info) => {
return Event.find({
take: req.filter.limit
take: req.filter.limit,
where: (req.filter && req.filter.owner) ? `"ownerId"='${req.filter.owner}'` : null
})
},
},

26
server/src/UserStories.md Normal file
View file

@ -0,0 +1,26 @@
# User Stories
Abbreviations:
## Mile Stone I (MVP)
### Event Owner specific user stories
-[ ] As an event owner I would like to be able to log in using my email, so that I can manage my events
-[ ] As an event owner I would like to see an overview of my events
-[ ] As an event owner I would like to be able to create a simple event
-[ ] As an event owner I would like to be able to update any event that I own
-[ ] As an event owner I would like to create a repeating event
-[ ] As an event owner I would like to be able to mark event as scheduled or as cancelled
-[ ] As an event owner I would like to be able to delete any event that I own
### Public user specific user stories
-[ ] As a user I would like to see an overview of events for the following month
-[ ] As a user I would like to view events in calendar mode, so that I get a quick overview of the activities
-[ ] As a user I would like to view events in list mode, so that I can see all events in chronological order
## Mile Stone II
-[ ] As an event owner I would like to put my event under a category
-[ ] As an event owner I would like to add tags to my events, so to be easily found by users looking for certain characteristics such as _free_, _kids-friendly_ etc'.
-[ ] As an user I expect tags to be displayed in the local language of the board but also in my language so that I can understand it best.

View file

@ -93,6 +93,7 @@ type Contact {
input EventsQueryFilter {
limit: Int
owner: ID
}
input EventTimeInput {