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
*/
export function isLocked (parent: any, { dataSources, req }: { dataSources: any; req: any }) {
return dataSources.userAPI.getUserId(LockUtils.getToken(req)).then((value: number) => {
return value !== parent.lockedBy && new Date() <= new Date(parent.lockedUntil);
});
return req.userId !== 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> {

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

@ -1,7 +1,7 @@
import { GraphQLError } from 'graphql';
import { Permission } from '../datasources/userserver/permission';
import { Person } from '../model/Person';
import { isLocked } from '../datasources/db/utils';
import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default {
Query: {
@ -42,6 +42,7 @@ export default {
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 })
},
ContactInformation: {
@ -52,6 +53,7 @@ export default {
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 })
},
Mutation: {

@ -1,7 +1,7 @@
import { Permission } from '../datasources/userserver/permission';
import { GraphQLError } from 'graphql';
import { LendingStation } from '../model/LendingStation';
import { isLocked } from '../datasources/db/utils';
import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default {
Query: {
@ -77,6 +77,7 @@ export default {
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 })
},
LoanPeriod: {
@ -106,6 +107,7 @@ export default {
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 })
},
Mutation: {

@ -1,6 +1,6 @@
import { GraphQLError } from 'graphql';
import { Permission } from '../datasources/userserver/permission';
import { isLocked } from '../datasources/db/utils';
import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default {
Query: {
@ -69,6 +69,7 @@ export default {
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 })
},
Engagement: {
@ -100,6 +101,7 @@ export default {
const str = (parent.dateRange as string).split(',')[1].replace(')', '');
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 })
},
Mutation: {

@ -1,6 +1,6 @@
import { GraphQLError } from 'graphql';
import { Permission } from '../datasources/userserver/permission';
import { isLocked } from '../datasources/db/utils';
import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default {
Query: {
@ -55,6 +55,7 @@ export default {
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 })
},
Organisation: {
@ -79,6 +80,7 @@ export default {
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 })
},
Mutation: {

@ -1,6 +1,6 @@
import { Permission } from '../datasources/userserver/permission';
import { GraphQLError } from 'graphql';
import { isLocked } from '../datasources/db/utils';
import { isLocked, isLockedByMe } from '../datasources/db/utils';
import { Participant } from '../model/Participant';
export default {
@ -56,6 +56,7 @@ export default {
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 })
},
WorkshopType: {

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

Loading…
Cancel
Save