-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.graphql
566 lines (524 loc) · 15 KB
/
schema.graphql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
" For file uploads; automatically handled by graphql-yoga "
scalar File
" For void returns, handled by graphql-scalars "
scalar Void
" For RFC 3339 datetime strings, handled by graphql-scalars "
scalar DateTimeISO
" For JSON, handled by graphql-scalars "
scalar JSON
# #
# Enum types #
# #
" Roles used for authorization "
enum UserRole {
ADMIN
USER
CITIZEN
COMPANY
GUEST
POLICE
BANK
BORDER_CONTROL
TAX_OFFICE
POLITICS
TEACHER
}
" type of user "
enum UserType {
CITIZEN
COMPANY
GUEST
}
" state of employment offer "
enum EmploymentOfferState {
PENDING
REJECTED
}
" state of employment offer available to citizens "
enum EmploymentOfferStateCitizenInput {
PENDING
}
" state of employment offer available to companies "
enum EmploymentOfferStateCompanyInput {
PENDING
REJECTED
}
" action of BorderCrossing "
enum BorderCrossingAction {
ENTER
LEAVE
}
" type of vote "
enum VoteType {
" Every choice is rated individually between 0.0 and 1.0 "
CONSENSUS
" One choice is selected with 1.0, all others set to 0.0 "
RADIO
}
# #
# Object and Union types #
# #
" Ein Buch " # eslint-disable-next-line @graphql-eslint/strict-id-in-types
type Book {
title: String!
author: Author!
}
" Input type of a book "
input BookInput {
title: String!
author: String!
}
" Ein Author " # eslint-disable-next-line @graphql-eslint/strict-id-in-types
type Author {
name: String!
books: [Book!]!
}
" The current session "
type Session {
id: ID!
user: User
}
" Base type for users "
interface User {
type: UserType!
id: ID!
roles: [UserRole!]!
balance: Float!
" amount of virtual money that can be changed back to real money "
redemptionBalance: Float!
transactions: [Transaction!]!
}
" Information needed to identify a user "
input UserSignatureInput {
type: UserType!
id: String!
}
" Information needed to authenticate a user "
input CredentialsInput {
type: UserType!
id: ID!
password: String
}
" A guest user "
type GuestUser implements User {
type: UserType!
id: ID!
roles: [UserRole!]!
balance: Float!
" amount of virtual money that can be changed back to real money "
redemptionBalance: Float!
transactions: [Transaction!]!
name: String
enteredAt: DateTimeISO!
leftAt: DateTimeISO
}
" Input type of a guest "
input GuestUserInput {
balance: Float
name: String
}
" A citizen user "
type CitizenUser implements User {
type: UserType!
id: ID!
roles: [UserRole!]!
balance: Float!
" amount of virtual money that can be changed back to real money "
redemptionBalance: Float!
transactions: [Transaction!]!
firstName: String!
lastName: String!
name: String!
image: String!
employment: Employment
employmentOffers(
state: EmploymentOfferStateCitizenInput! = PENDING
): [EmploymentOffer!]!
" Whether the citizen is currently in the state "
isInState: Boolean!
" The amount of time the citizen spent in the state today up until now "
timeInState: Int!
}
" A company user "
type CompanyUser implements User {
type: UserType!
id: ID!
roles: [UserRole!]!
balance: Float!
" amount of virtual money that can be changed back to real money "
redemptionBalance: Float!
transactions: [Transaction!]!
drafts: [Draft!]!
name: String!
image: String!
products: [Product!]!
employer: Employment!
employees: [Employment!]!
employmentOffers(
state: EmploymentOfferStateCompanyInput!
): [EmploymentOffer!]!
stats: [CompanyStatsFragment!]!
}
" Representing a 1h timeframe of the company's stats "
type CompanyStatsFragment {
startOfHour: DateTimeISO!
staff: Float!
staffCost: Float!
grossRevenue: Float!
netRevenue: Float!
profit: Float!
}
" Information about a shift on an employee "
type Worktime {
id: ID!
employment: Employment!
start: DateTimeISO!
" If null, the shift has not yet ended "
end: DateTimeISO
}
" Contains information about an employment "
type Employment {
id: Int!
company: CompanyUser!
citizen: CitizenUser!
# dynamic values
" in seconds "
worktimeToday: Int!
" in seconds "
worktimeYesterday: Int!
# contract (static values)
" virtual currency per hour (employment contract) "
salary: Float!
" worktime per day in seconds (employment contract) "
minWorktime: Int!
}
" A employment offer "
type EmploymentOffer {
id: Int!
company: CompanyUser!
citizen: CitizenUser!
state: EmploymentOfferState!
" virtual currency per hour "
salary: Float!
" worktime per day in seconds "
minWorktime: Int!
}
" Input type for an employment offer "
input EmploymentOfferInput {
citizenId: ID!
" virtual currency per hour "
salary: Float!
" worktime per day in seconds "
minWorktime: Int!
}
" Base type for transactions"
interface Transaction {
id: Int!
date: DateTimeISO!
}
" Base type for transaction drafts "
interface Draft {
id: Int!
date: DateTimeISO!
}
" A transfer transaction "
type TransferTransaction implements Transaction {
id: Int!
date: DateTimeISO!
sender: User!
receiver: User!
value: Float!
purpose: String
}
" Input for a transfer transaction "
input TransferTransactionInput {
" receiver must be a citizen "
receiver: UserSignatureInput!
value: Float!
purpose: String
}
" A change transaction "
type ChangeTransaction implements Transaction {
id: Int!
date: DateTimeISO!
user: User!
fromCurrency: String!
fromValue: Float!
toCurrency: String!
toValue: Float!
clerk: CitizenUser
}
" The draft of a change transaction "
type ChangeDraft implements Draft {
id: Int!
date: DateTimeISO!
fromCurrency: String!
fromValue: Float!
toCurrency: String!
toValue: Float!
clerk: CitizenUser
}
" Input type of a change transaction "
input ChangeInput {
fromCurrency: String!
fromValue: Float!
toCurrency: String!
" citizen id of clerk "
clerk: ID
}
" A purchase transaction "
type PurchaseTransaction implements Transaction {
id: Int!
date: DateTimeISO!
customer: User!
company: CompanyUser!
grossPrice: Float!
netPrice: Float!
tax: Float!
items: [PurchaseItem!]!
discount: Float
}
" The draft of a purchase transaction "
type PurchaseDraft implements Draft {
id: Int!
date: DateTimeISO!
company: CompanyUser!
grossPrice: Float!
netPrice: Float!
tax: Float!
items: [PurchaseItem!]!
discount: Float!
}
" Input type of a purchase transaction "
input PurchaseInput {
items: [PurchaseItemInput!]!
discount: Float
}
" Input type of a purchase at warehouse transaction "
input WarehousePurchaseInput {
items: [PurchaseItemInput!]!
}
" Tuple with product and amount for use in purchases " # eslint-disable-next-line @graphql-eslint/strict-id-in-types
type PurchaseItem {
product: Product!
amount: Int!
}
" Tuple with product and amount for use in purchases "
input PurchaseItemInput {
product: ProductRevisionInput!
amount: Int!
}
" A customs transaction "
type CustomsTransaction implements Transaction {
id: Int!
date: DateTimeISO!
user: User!
customs: Float!
}
" Input type for customs transaction "
input CustomsInput {
user: UserSignatureInput!
customs: Float!
}
" A salary transaction "
type SalaryTransaction implements Transaction {
id: Int!
date: DateTimeISO!
employment: Employment!
grossValue: Float!
netValue: Float!
tax: Float!
" If null, it is a bonus payment "
worktime: Worktime
isBonus: Boolean!
}
" return type for registerBorderCrossing mutation " # eslint-disable-next-line @graphql-eslint/strict-id-in-types
type BorderCrossing {
citizen: CitizenUser!
action: BorderCrossingAction!
date: DateTimeISO!
}
" Information about the entering and leaving of a citizen "
type Stay {
id: Int!
citizen: CitizenUser!
enteredAt: DateTimeISO!
leftAt: DateTimeISO
}
" A product of an company "
type Product {
id: ID!
revision: ID!
company: CompanyUser!
name: String!
price: Float!
deleted: Boolean!
salesToday: Int!
salesTotal: Int!
salesPerDay: Float!
grossRevenueTotal: Float!
stats: [ProductStatsFragment!]!
}
" Input type for Product "
input ProductInput {
name: String!
price: Float!
}
" Information needed to identify a product revision "
input ProductRevisionInput {
id: ID!
revision: ID!
}
" Representing a 1h timeframe of the product's stats"
type ProductStatsFragment {
startOfHour: DateTimeISO!
sales: Int!
grossRevenue: Float!
}
" A vote "
type Vote {
id: ID!
type: VoteType!
title: String!
description: String!
image: String!
endAt: DateTimeISO!
choices: [String!]!
" Vote of current user, if he voted "
# eslint-disable-next-line @graphql-eslint/no-typename-prefix
votingPaper: [Float!]
" Result taking all votes into account, if the vote has endet "
result: [Float!]
chartInfo: String
}
" Input for createVote mutation "
input VoteInput {
type: VoteType!
title: String!
description: String!
image: File!
endAt: DateTimeISO!
choices: [String!]!
}
" Information of an id card "
type Card {
id: ID!
user: User
blocked: Boolean!
}
# #
# API Root types #
# #
" Queries "
type Query {
books: [Book!]!
book(title: String!): Book
authors: [Author!]!
author(name: String!): Author
" Current session information. "
session: Session!
" Currently logged in user. Authorized: user "
me: User!
" Currently logged in guest. Authorized: guest "
meGuest: GuestUser!
" Currently logged in citizen. Authorized: citizen "
meCitizen: CitizenUser!
" Currently logged in company. Authorized: company "
meCompany: CompanyUser!
" Check validity of credentials including password. "
checkCredentials(credentials: CredentialsInput!): User!
user(user: UserSignatureInput!): User!
" Citizens belonging to given class. Authorized: teacher, admin "
citizensByClass(class: String!): [CitizenUser!]!
" All companies. Authorized: tax office, admin "
companies: [CompanyUser!]!
" Information on all votes. Authorized: citizen, political admin "
votes: [Vote!]!
" Reads user assigned to card, if any. "
readCard(id: ID!): User
" Read card information. Authorized: border control, admin "
card(id: ID!): Card!
}
" Mutations "
type Mutation {
addBook(book: BookInput!): Book!
" Login as user, successive calls are possible. Guests must no specify a password "
login(credentials: CredentialsInput!): Session!
" Logout as user, succeessive calls are possible. Autorized: user "
logout: Session!
" Create employment offer. Authorized: company "
createEmploymentOffer(offer: EmploymentOfferInput!): EmploymentOffer!
" Accept employment offer. Authorized: citizen"
acceptEmploymentOffer(id: Int!): Employment!
" Reject employment offer. Authorized: citizen"
rejectEmploymentOffer(id: Int!, reason: String): EmploymentOffer!
" Delete rejected employment offer. Authorized: company "
deleteEmploymentOffer(id: Int!): Void
" Cancel employment. Authorized: company or citizen "
cancelEmployment(id: Int!): Void
" Pay bonus to employees. Authorized: company "
payBonus(value: Float!, employmentIds: [Int!]!): [SalaryTransaction!]!
" Create change transaction draft. Authorized: bank "
changeCurrencies(change: ChangeInput!): ChangeDraft!
" Pay a change transaction draft. Authorized: bank (with credentials), user (without credentials) "
payChangeDraft(id: Int!, credentials: CredentialsInput): ChangeTransaction!
" Delete a change transaction draft. Authorized: bank "
deleteChangeDraft(id: Int!): Void
" Transfer money to another citizen. Authorized: citizen "
transferMoney(transfer: TransferTransactionInput!): TransferTransaction!
" Create a purchase draft. Authorized: company "
sell(purchase: PurchaseInput!): PurchaseDraft!
" Pay a purchase transaction draft. Only selling company must specify explicit user. "
payPurchaseDraft(
id: Int!
credentials: CredentialsInput
): PurchaseTransaction!
" Delete a purchase draft. Authorized: issuing company"
deletePurchaseDraft(id: Int!): Void
" Order products at the warehouse for the next day. Authorized: company "
warehousePurchase(purchase: WarehousePurchaseInput!): PurchaseTransaction!
" Charge customs on border crossings. Authorized: border control "
chargeCustoms(customs: CustomsInput!): CustomsTransaction!
" Register citizens crossing the border to track compulsory attendance. Authorized: border control "
registerBorderCrossing(citizenId: ID!): BorderCrossing!
" Register all citizens leaving the state. Used at the end of the opening ours. Authorized: admin "
leaveAllCitizens: [Stay!]!
" Create a new guest account and register him entering. Authorized: border control, admin "
createGuest(guest: GuestUserInput!): GuestUser!
" Register a guest leaving. Authorized: border control, admin "
leaveGuest(id: ID!): GuestUser!
" Add product to company's inventory. Authorized: company "
addProduct(product: ProductInput!): Product!
" Edit product of company's inventory. Authorized: owning company "
editProduct(id: ID!, product: ProductInput!): Product!
" Remove product from company's inventory. Authorized: owning company "
removeProduct(id: ID!): Void
" Create a vote. Authorized: political admin "
createVote(vote: VoteInput!): Vote!
" Delete a vote. Authorized: political admin "
deleteVote(id: ID!): Void
" Cast your vote. Authorized: citizen "
castVote(id: ID!, votingPaper: [Float!]!): Vote!
" Register a new empty unblocked card. Authorized: admin "
registerCard(id: ID!): Card!
" Assign a user to a card. Authorized: border control, admin "
assignCard(id: ID!, user: UserSignatureInput!): Card!
" Unassign a user from a card. The card becomes empty egain. Authorized: border control, admin "
unassignCard(id: ID!): Card!
" Block card preventing its further use. Authorized: admin "
blockCard(id: ID!): Card!
" Unblock card reenabling it use. Authorized: admin "
unblockCard(id: ID!): Card!
" Backup the database. Usually not needed because of automatic backups. Authorized: admin "
backupDatabase: Void
" Execute sql query. Backups the database before. Requires config `database.allowRawSql`. Authorized: admin "
execDatabase(sql: String!): JSON!
" Reload the server configuration. Backups the database before. Authorized: admin "
reloadConfig: Void
" Reset the password of an citizen or company. Authorized: admin "
resetPassword(user: UserSignatureInput!, password: String!): User!
}
" Subscriptions "
type Subscription {
addedBook(author: String): Book!
}