isLockedByMe

pull/14/head
leonnicolas 4 years ago
parent 5f19ddbb1b
commit 5a52f592cb
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -25,9 +25,11 @@ export function genDateRange (struct: any) {
* @param req user request * @param req user request
*/ */
export function isLocked (parent: any, { dataSources, req }: { dataSources: any; req: any }) { export function isLocked (parent: any, { dataSources, req }: { dataSources: any; req: any }) {
return dataSources.userAPI.getUserId(LockUtils.getToken(req)).then((value: number) => { return req.userId !== parent.lockedBy && new Date() <= new Date(parent.lockedUntil);
return value !== parent.lockedBy && new Date() <= new Date(parent.lockedUntil); }
});
export function isLockedByMe (parent: any, { dataSources, req }: { dataSources: any; req: any }) {
return req.userId === parent.lockedBy && new Date() <= new Date(parent.lockedUntil);
} }
export async function deleteEntity (connection: Connection, target: ObjectType<Lockable>, alias: string, id: number, userId: number): Promise<Boolean> { export async function deleteEntity (connection: Connection, target: ObjectType<Lockable>, alias: string, id: number, userId: number): Promise<Boolean> {

@ -1,6 +1,6 @@
import { Permission } from '../datasources/userserver/permission'; import { Permission } from '../datasources/userserver/permission';
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { isLocked } from '../datasources/db/utils'; import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default { export default {
Query: { Query: {
@ -119,6 +119,7 @@ export default {
} }
}, },
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }), isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }),
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
timeFrames (parent: any, __: any, { dataSources, req }: { dataSources: any, req: any }) { timeFrames (parent: any, __: any, { dataSources, req }: { dataSources: any, req: any }) {
if (req.permissions.includes(Permission.ReadTimeFrame)) { if (req.permissions.includes(Permission.ReadTimeFrame)) {
return dataSources.lendingStationAPI.timeFramesByCargoBikeId(parent.id); return dataSources.lendingStationAPI.timeFramesByCargoBikeId(parent.id);
@ -150,6 +151,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
BikeEvent: { BikeEvent: {
@ -181,9 +183,11 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
BikeEventType: { BikeEventType: {
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
Mutation: { Mutation: {

@ -1,7 +1,7 @@
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { Permission } from '../datasources/userserver/permission'; import { Permission } from '../datasources/userserver/permission';
import { Person } from '../model/Person'; import { Person } from '../model/Person';
import { isLocked } from '../datasources/db/utils'; import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default { export default {
Query: { Query: {
@ -42,6 +42,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
ContactInformation: { ContactInformation: {
@ -52,6 +53,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
Mutation: { Mutation: {

@ -1,7 +1,7 @@
import { Permission } from '../datasources/userserver/permission'; import { Permission } from '../datasources/userserver/permission';
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { LendingStation } from '../model/LendingStation'; import { LendingStation } from '../model/LendingStation';
import { isLocked } from '../datasources/db/utils'; import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default { export default {
Query: { Query: {
@ -77,6 +77,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
LoanPeriod: { LoanPeriod: {
@ -106,6 +107,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
Mutation: { Mutation: {

@ -1,6 +1,6 @@
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { Permission } from '../datasources/userserver/permission'; import { Permission } from '../datasources/userserver/permission';
import { isLocked } from '../datasources/db/utils'; import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default { export default {
Query: { Query: {
@ -69,6 +69,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
Engagement: { Engagement: {
@ -100,6 +101,7 @@ export default {
const str = (parent.dateRange as string).split(',')[1].replace(')', ''); const str = (parent.dateRange as string).split(',')[1].replace(')', '');
return (str.length > 0) ? str : null; return (str.length > 0) ? str : null;
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
Mutation: { Mutation: {

@ -1,6 +1,6 @@
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { Permission } from '../datasources/userserver/permission'; import { Permission } from '../datasources/userserver/permission';
import { isLocked } from '../datasources/db/utils'; import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default { export default {
Query: { Query: {
@ -55,6 +55,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
Organisation: { Organisation: {
@ -79,6 +80,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
Mutation: { Mutation: {

@ -1,6 +1,6 @@
import { Permission } from '../datasources/userserver/permission'; import { Permission } from '../datasources/userserver/permission';
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { isLocked } from '../datasources/db/utils'; import { isLocked, isLockedByMe } from '../datasources/db/utils';
import { Participant } from '../model/Participant'; import { Participant } from '../model/Participant';
export default { export default {
@ -56,6 +56,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
isLockedByMe: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLockedByMe(parent, { dataSources, req }),
isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req }) isLocked: (parent: any, __: any, { dataSources, req }: { dataSources: any; req: any }) => isLocked(parent, { dataSources, req })
}, },
WorkshopType: { WorkshopType: {

@ -48,6 +48,7 @@ type CargoBike {
engagement(offset: Int!, limit: Int!): [Engagement] engagement(offset: Int!, limit: Int!): [Engagement]
timeFrames: [TimeFrame] timeFrames: [TimeFrame]
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -327,6 +328,7 @@ type Participant {
engagement: [Engagement] engagement: [Engagement]
workshops: [Workshop] workshops: [Workshop]
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -376,6 +378,7 @@ type Workshop {
trainer2: Participant trainer2: Participant
participants: [Participant] participants: [Participant]
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -405,6 +408,7 @@ type WorkshopType {
id: ID! id: ID!
name: String! name: String!
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -424,6 +428,7 @@ type EngagementType {
name: String! name: String!
description: String! description: String!
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -449,6 +454,7 @@ type Engagement {
participant: Participant! participant: Participant!
cargoBike: CargoBike! cargoBike: CargoBike!
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -504,6 +510,7 @@ type Equipment {
description: String description: String
cargoBike: CargoBike cargoBike: CargoBike
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -531,6 +538,7 @@ type EquipmentType {
name: String! name: String!
description: String! description: String!
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -563,6 +571,7 @@ type BikeEvent {
documents: [String]! documents: [String]!
remark: String remark: String
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -601,6 +610,7 @@ input BikeEventUpdateInput {
type BikeEventType { type BikeEventType {
id: ID! id: ID!
name: String! name: String!
isLockedByMe: Boolean!
isLocked: Boolean! isLocked: Boolean!
lockedUntil: Date lockedUntil: Date
} }
@ -619,6 +629,7 @@ type Provider {
organisation: Organisation organisation: Organisation
cargoBikes: [CargoBike] cargoBikes: [CargoBike]
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -652,6 +663,7 @@ type Person {
firstName: String! firstName: String!
contactInformation: [ContactInformation] contactInformation: [ContactInformation]
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -678,6 +690,7 @@ type ContactInformation {
email2: String email2: String
note: String note: String
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -717,6 +730,7 @@ type Organisation {
contactInformation: ContactInformation contactInformation: ContactInformation
otherData: String otherData: String
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -760,6 +774,7 @@ type LendingStation {
numCargoBikes: Int! numCargoBikes: Int!
organisation: Organisation organisation: Organisation
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -830,6 +845,7 @@ type TimeFrame {
lendingStation: LendingStation! lendingStation: LendingStation!
cargoBike: CargoBike! cargoBike: CargoBike!
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date

Loading…
Cancel
Save