Fixed DateTime properties

This commit is contained in:
Douglas Barone 2020-11-10 16:35:54 -04:00
parent 5d86d2785d
commit 1a69ad12e0
19 changed files with 82 additions and 533 deletions

View File

@ -1,95 +0,0 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = "***"
}
model ResetToken {
id Int @id @default(autoincrement())
token String @unique
expiration DateTime
usedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], name: "resettoken_to_user")
userId Int
creator User @relation(fields: [creatorId], references: [id], name: "resettoken_to_creator")
creatorId Int
}
model User {
id Int @id @default(autoincrement())
lastLogin DateTime?
lastLoginPrior DateTime?
roles Json?
groups Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
accountExpires String?
badPasswordTime String?
badPwdCount String?
cn String?
department String?
description String?
displayName String?
distinguishedName String?
dn String?
extensionAttribute1 String?
extensionAttribute10 String?
extensionAttribute2 String?
extensionAttribute6 String?
extensionAttribute7 String?
givenName String?
homeDirectory String?
homeDrive String?
lastLogoff String?
lastLogon String?
lastLogonTimestamp String?
lockoutTime String?
logonCount String?
mail String?
name String?
objectCategory String?
objectGUID String?
objectSid String?
primaryGroupID String?
pwdLastSet String?
sAMAccountName String @unique
sAMAccountType String?
sn String?
thumbnailPhoto String?
title String?
userAccountControl String?
userPrincipalName String?
whenChanged String?
whenCreated String?
createdTokens ResetToken[] @relation("resettoken_to_user")
tokens ResetToken[] @relation("resettoken_to_creator")
WifiDevice WifiDevice[]
}
model WifiDevice {
id Int @id @default(autoincrement())
oui String?
mac String? @unique
hostname String?
firstSeen String?
lastSeen String?
essid String?
ip String?
uptime String?
apName String?
status Status?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId Int
user User @relation(fields: [userId], references: [id])
}
enum Status {
ONLINE
OFFLINE
}

View File

@ -1,50 +0,0 @@
# Migration `20201107123940-init`
This migration has been generated by Douglas Barone at 11/7/2020, 8:39:40 AM.
You can check out the [state of the schema](./schema.prisma) after the migration.
## Database Steps
```sql
```
## Changes
```diff
diff --git schema.prisma schema.prisma
migration 20201106194210-init..20201107123940-init
--- datamodel.dml
+++ datamodel.dml
@@ -3,9 +3,9 @@
}
datasource db {
provider = "postgresql"
- url = "***"
+ url = "***"
}
model ResetToken {
id Int @id @default(autoincrement())
@@ -67,9 +67,9 @@
whenChanged String?
whenCreated String?
createdTokens ResetToken[] @relation("resettoken_to_user")
tokens ResetToken[] @relation("resettoken_to_creator")
- WifiDevice WifiDevice[]
+ WifiDevice WifiDevice[] @relation("wifidevice_to_user")
}
model WifiDevice {
id Int @id @default(autoincrement())
@@ -85,9 +85,9 @@
status Status?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId Int
- user User @relation(fields: [userId], references: [id])
+ user User @relation(fields: [userId], references: [id], name: "wifidevice_to_user")
}
enum Status {
ONLINE
```

View File

@ -1,95 +0,0 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = "***"
}
model ResetToken {
id Int @id @default(autoincrement())
token String @unique
expiration DateTime
usedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], name: "resettoken_to_user")
userId Int
creator User @relation(fields: [creatorId], references: [id], name: "resettoken_to_creator")
creatorId Int
}
model User {
id Int @id @default(autoincrement())
lastLogin DateTime?
lastLoginPrior DateTime?
roles Json?
groups Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
accountExpires String?
badPasswordTime String?
badPwdCount String?
cn String?
department String?
description String?
displayName String?
distinguishedName String?
dn String?
extensionAttribute1 String?
extensionAttribute10 String?
extensionAttribute2 String?
extensionAttribute6 String?
extensionAttribute7 String?
givenName String?
homeDirectory String?
homeDrive String?
lastLogoff String?
lastLogon String?
lastLogonTimestamp String?
lockoutTime String?
logonCount String?
mail String?
name String?
objectCategory String?
objectGUID String?
objectSid String?
primaryGroupID String?
pwdLastSet String?
sAMAccountName String @unique
sAMAccountType String?
sn String?
thumbnailPhoto String?
title String?
userAccountControl String?
userPrincipalName String?
whenChanged String?
whenCreated String?
createdTokens ResetToken[] @relation("resettoken_to_user")
tokens ResetToken[] @relation("resettoken_to_creator")
WifiDevice WifiDevice[] @relation("wifidevice_to_user")
}
model WifiDevice {
id Int @id @default(autoincrement())
oui String?
mac String? @unique
hostname String?
firstSeen String?
lastSeen String?
essid String?
ip String?
uptime String?
apName String?
status Status?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId Int
user User @relation(fields: [userId], references: [id], name: "wifidevice_to_user")
}
enum Status {
ONLINE
OFFLINE
}

View File

@ -1,44 +0,0 @@
{
"version": "0.3.14-fixed",
"steps": [
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "User",
"field": "WifiDevice"
},
"directive": "relation"
}
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "User",
"field": "WifiDevice"
},
"directive": "relation"
},
"argument": "",
"value": "\"wifidevice_to_user\""
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "WifiDevice",
"field": "user"
},
"directive": "relation"
},
"argument": "name",
"value": "\"wifidevice_to_user\""
}
]
}

View File

@ -1,40 +0,0 @@
# Migration `20201107124332-init`
This migration has been generated by Douglas Barone at 11/7/2020, 8:43:32 AM.
You can check out the [state of the schema](./schema.prisma) after the migration.
## Database Steps
```sql
ALTER TABLE "public"."WifiDevice" ALTER COLUMN "mac" SET NOT NULL
```
## Changes
```diff
diff --git schema.prisma schema.prisma
migration 20201107123940-init..20201107124332-init
--- datamodel.dml
+++ datamodel.dml
@@ -3,9 +3,9 @@
}
datasource db {
provider = "postgresql"
- url = "***"
+ url = "***"
}
model ResetToken {
id Int @id @default(autoincrement())
@@ -73,9 +73,9 @@
model WifiDevice {
id Int @id @default(autoincrement())
oui String?
- mac String? @unique
+ mac String @unique
hostname String?
firstSeen String?
lastSeen String?
essid String?
```

View File

@ -1,11 +0,0 @@
{
"version": "0.3.14-fixed",
"steps": [
{
"tag": "UpdateField",
"model": "WifiDevice",
"field": "mac",
"arity": "Required"
}
]
}

View File

@ -1,42 +0,0 @@
# Migration `20201110184959-init`
This migration has been generated by Douglas Barone at 11/10/2020, 2:49:59 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.
## Database Steps
```sql
ALTER TABLE "public"."WifiDevice" ALTER COLUMN "userId" DROP NOT NULL
```
## Changes
```diff
diff --git schema.prisma schema.prisma
migration 20201107124332-init..20201110184959-init
--- datamodel.dml
+++ datamodel.dml
@@ -3,9 +3,9 @@
}
datasource db {
provider = "postgresql"
- url = "***"
+ url = "***"
}
model ResetToken {
id Int @id @default(autoincrement())
@@ -84,10 +84,10 @@
apName String?
status Status?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
- userId Int
- user User @relation(fields: [userId], references: [id], name: "wifidevice_to_user")
+ userId Int?
+ user User? @relation(fields: [userId], references: [id], name: "wifidevice_to_user")
}
enum Status {
ONLINE
```

View File

@ -1,95 +0,0 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = "***"
}
model ResetToken {
id Int @id @default(autoincrement())
token String @unique
expiration DateTime
usedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], name: "resettoken_to_user")
userId Int
creator User @relation(fields: [creatorId], references: [id], name: "resettoken_to_creator")
creatorId Int
}
model User {
id Int @id @default(autoincrement())
lastLogin DateTime?
lastLoginPrior DateTime?
roles Json?
groups Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
accountExpires String?
badPasswordTime String?
badPwdCount String?
cn String?
department String?
description String?
displayName String?
distinguishedName String?
dn String?
extensionAttribute1 String?
extensionAttribute10 String?
extensionAttribute2 String?
extensionAttribute6 String?
extensionAttribute7 String?
givenName String?
homeDirectory String?
homeDrive String?
lastLogoff String?
lastLogon String?
lastLogonTimestamp String?
lockoutTime String?
logonCount String?
mail String?
name String?
objectCategory String?
objectGUID String?
objectSid String?
primaryGroupID String?
pwdLastSet String?
sAMAccountName String @unique
sAMAccountType String?
sn String?
thumbnailPhoto String?
title String?
userAccountControl String?
userPrincipalName String?
whenChanged String?
whenCreated String?
createdTokens ResetToken[] @relation("resettoken_to_user")
tokens ResetToken[] @relation("resettoken_to_creator")
WifiDevice WifiDevice[] @relation("wifidevice_to_user")
}
model WifiDevice {
id Int @id @default(autoincrement())
oui String?
mac String @unique
hostname String?
firstSeen String?
lastSeen String?
essid String?
ip String?
uptime String?
apName String?
status Status?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId Int?
user User? @relation(fields: [userId], references: [id], name: "wifidevice_to_user")
}
enum Status {
ONLINE
OFFLINE
}

View File

@ -1,17 +0,0 @@
{
"version": "0.3.14-fixed",
"steps": [
{
"tag": "UpdateField",
"model": "WifiDevice",
"field": "userId",
"arity": "Optional"
},
{
"tag": "UpdateField",
"model": "WifiDevice",
"field": "user",
"arity": "Optional"
}
]
}

View File

@ -1,6 +1,6 @@
# Migration `20201106194210-init`
# Migration `20201110194349-init`
This migration has been generated by Douglas Barone at 11/6/2020, 3:42:10 PM.
This migration has been generated by Douglas Barone at 11/10/2020, 3:43:49 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.
## Database Steps
@ -54,7 +54,7 @@ CREATE TABLE "public"."User" (
"objectGUID" text ,
"objectSid" text ,
"primaryGroupID" text ,
"pwdLastSet" text ,
"pwdLastSet" timestamp(3) ,
"sAMAccountName" text NOT NULL ,
"sAMAccountType" text ,
"sn" text ,
@ -70,10 +70,10 @@ PRIMARY KEY ("id")
CREATE TABLE "public"."WifiDevice" (
"id" SERIAL,
"oui" text ,
"mac" text ,
"mac" text NOT NULL ,
"hostname" text ,
"firstSeen" text ,
"lastSeen" text ,
"firstSeen" timestamp(3) ,
"lastSeen" timestamp(3) ,
"essid" text ,
"ip" text ,
"uptime" text ,
@ -81,7 +81,7 @@ CREATE TABLE "public"."WifiDevice" (
"status" "Status" ,
"createdAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" timestamp(3) NOT NULL ,
"userId" integer NOT NULL ,
"userId" integer ,
PRIMARY KEY ("id")
)
@ -95,14 +95,14 @@ ALTER TABLE "public"."ResetToken" ADD FOREIGN KEY("userId")REFERENCES "public"."
ALTER TABLE "public"."ResetToken" ADD FOREIGN KEY("creatorId")REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE
ALTER TABLE "public"."WifiDevice" ADD FOREIGN KEY("userId")REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE
ALTER TABLE "public"."WifiDevice" ADD FOREIGN KEY("userId")REFERENCES "public"."User"("id") ON DELETE SET NULL ON UPDATE CASCADE
```
## Changes
```diff
diff --git schema.prisma schema.prisma
migration ..20201106194210-init
migration ..20201110194349-init
--- datamodel.dml
+++ datamodel.dml
@@ -1,0 +1,95 @@
@ -164,7 +164,7 @@ migration ..20201106194210-init
+ objectGUID String?
+ objectSid String?
+ primaryGroupID String?
+ pwdLastSet String?
+ pwdLastSet DateTime?
+ sAMAccountName String @unique
+ sAMAccountType String?
+ sn String?
@ -176,16 +176,16 @@ migration ..20201106194210-init
+ whenCreated String?
+ createdTokens ResetToken[] @relation("resettoken_to_user")
+ tokens ResetToken[] @relation("resettoken_to_creator")
+ WifiDevice WifiDevice[]
+ WifiDevice WifiDevice[] @relation("wifidevice_to_user")
+}
+
+model WifiDevice {
+ id Int @id @default(autoincrement())
+ oui String?
+ mac String? @unique
+ mac String @unique
+ hostname String?
+ firstSeen String?
+ lastSeen String?
+ firstSeen DateTime?
+ lastSeen DateTime?
+ essid String?
+ ip String?
+ uptime String?
@ -193,8 +193,8 @@ migration ..20201106194210-init
+ status Status?
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ userId Int
+ user User @relation(fields: [userId], references: [id])
+ userId Int?
+ user User? @relation(fields: [userId], references: [id], name: "wifidevice_to_user")
+}
+
+enum Status {

View File

@ -56,7 +56,7 @@ model User {
objectGUID String?
objectSid String?
primaryGroupID String?
pwdLastSet String?
pwdLastSet DateTime?
sAMAccountName String @unique
sAMAccountType String?
sn String?
@ -76,8 +76,8 @@ model WifiDevice {
oui String?
mac String @unique
hostname String?
firstSeen String?
lastSeen String?
firstSeen DateTime?
lastSeen DateTime?
essid String?
ip String?
uptime String?
@ -85,8 +85,8 @@ model WifiDevice {
status Status?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId Int
user User @relation(fields: [userId], references: [id], name: "wifidevice_to_user")
userId Int?
user User? @relation(fields: [userId], references: [id], name: "wifidevice_to_user")
}
enum Status {

View File

@ -619,7 +619,7 @@
"tag": "CreateField",
"model": "User",
"field": "pwdLastSet",
"type": "String",
"type": "DateTime",
"arity": "Optional"
},
{
@ -767,6 +767,31 @@
"type": "WifiDevice",
"arity": "List"
},
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "User",
"field": "WifiDevice"
},
"directive": "relation"
}
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "User",
"field": "WifiDevice"
},
"directive": "relation"
},
"argument": "",
"value": "\"wifidevice_to_user\""
},
{
"tag": "CreateModel",
"model": "WifiDevice"
@ -826,7 +851,7 @@
"model": "WifiDevice",
"field": "mac",
"type": "String",
"arity": "Optional"
"arity": "Required"
},
{
"tag": "CreateDirective",
@ -850,14 +875,14 @@
"tag": "CreateField",
"model": "WifiDevice",
"field": "firstSeen",
"type": "String",
"type": "DateTime",
"arity": "Optional"
},
{
"tag": "CreateField",
"model": "WifiDevice",
"field": "lastSeen",
"type": "String",
"type": "DateTime",
"arity": "Optional"
},
{
@ -950,14 +975,14 @@
"model": "WifiDevice",
"field": "userId",
"type": "Int",
"arity": "Required"
"arity": "Optional"
},
{
"tag": "CreateField",
"model": "WifiDevice",
"field": "user",
"type": "User",
"arity": "Required"
"arity": "Optional"
},
{
"tag": "CreateDirective",
@ -997,6 +1022,20 @@
},
"argument": "references",
"value": "[id]"
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "WifiDevice",
"field": "user"
},
"directive": "relation"
},
"argument": "name",
"value": "\"wifidevice_to_user\""
}
]
}

View File

@ -1,6 +1,3 @@
# Prisma Migrate lockfile v1
20201106194210-init
20201107123940-init
20201107124332-init
20201110184959-init
20201110194349-init

View File

@ -56,7 +56,7 @@ model User {
objectGUID String?
objectSid String?
primaryGroupID String?
pwdLastSet String?
pwdLastSet DateTime?
sAMAccountName String @unique
sAMAccountType String?
sn String?
@ -76,8 +76,8 @@ model WifiDevice {
oui String?
mac String @unique
hostname String?
firstSeen String?
lastSeen String?
firstSeen DateTime?
lastSeen DateTime?
essid String?
ip String?
uptime String?

View File

@ -1,6 +1,6 @@
import { updateDBWithOnlineDevices } from '../utils/wifiUtils'
import { User } from '../classes/User'
import { gql } from 'apollo-server'
import prisma from '../prisma'
const parseSAMAccountName = sAMAccountName =>
@ -99,10 +99,11 @@ const Query = {
// })
return prisma.wifiDevices({
orderBy: 'lastSeen_DESC',
orderBy: [{ lastSeen: 'desc' }],
where: identifiedOnly ? { NOT: { user: null } } : {}
})
},
userPresence: async (_, { search }) => {
if (!search) {
await updateDBWithOnlineDevices()
@ -113,7 +114,7 @@ const Query = {
where: {
WifiDevice: { some: { lastSeen: { not: null } } }
},
include: { WifiDevice: true }
include: { WifiDevice: { orderBy: [{ lastSeen: 'desc' }] } }
})
const userPresences = usersWithWifiDevices
@ -126,9 +127,7 @@ const Query = {
displayName: user.displayName,
thumbnailPhoto: user.thumbnailPhoto
},
wifiDevices: user.WifiDevice.sort((a, b) =>
a.lastSeen > b.lastSeen ? -1 : 1
)
wifiDevices: user.WifiDevice
}))
const sortedUserPresences = userPresences.sort((a, b) =>

View File

@ -9,6 +9,7 @@ const User = {
lastLogin: _ => _.lastLogin.toISOString(),
lastLoginPrior: _ => _.lastLoginPrior.toISOString(),
pwdLastSet: _ => _.pwdLastSet.toISOString(),
sharedFolders: _ =>
_.groups

View File

@ -1,7 +1,9 @@
import prisma from '../prisma'
const WifiDevice = {
user: _ => prisma.wifiDevice.findOne({ where: { id: _.id } }).User()
user: _ => prisma.wifiDevice.findOne({ where: { id: _.id } }).User(),
lastSeen: _ => _.lastSeen.toISOString(),
firstSeen: _ => _.firstSeen.toISOString()
}
export { WifiDevice }

View File

@ -28,7 +28,7 @@ class AuthDirective extends SchemaDirectiveVisitor {
context.auth = user
if (user.pwdLastSet === pwdLastSet) {
if (user.pwdLastSet.toISOString() === pwdLastSet) {
if (
expectedRoles.length === 0 ||
expectedRoles.some(role => user.roles.includes(role))

View File

@ -18,8 +18,8 @@ const getOnlineWifiDevices = async () => {
oui: client.oui,
mac: client.mac,
hostname: client.hostname,
firstSeen: new Date(client.first_seen * 1000).toISOString(),
lastSeen: new Date(client.last_seen * 1000).toISOString(),
firstSeen: new Date(client.first_seen * 1000),
lastSeen: new Date(client.last_seen * 1000),
essid: client.essid,
ip: client.ip,
uptime: client.uptime.toString(),