Replaced momentjs with date-fns in web.

This commit is contained in:
Douglas Barone 2020-11-09 12:05:21 -04:00
parent 55743014e7
commit 07aaf99c17
13 changed files with 71 additions and 52 deletions

View File

@ -269,7 +269,7 @@ class User {
const jwtSecret = process.env.JWT_SECRET || 'a good secret' const jwtSecret = process.env.JWT_SECRET || 'a good secret'
//@TODO Add momentJs to calculate expiration // TODO: Add date-fns to calculate expiration
const options = { expiresIn: process.env.JWT_EXPIRATION || '72h' } const options = { expiresIn: process.env.JWT_EXPIRATION || '72h' }
const token = jwt.sign(payload, jwtSecret, options) const token = jwt.sign(payload, jwtSecret, options)

View File

@ -7,6 +7,9 @@ const User = {
groups: async (_, args, { ad }) => groups: async (_, args, { ad }) =>
_.groups ? _.groups : ad.getGroupMembershipForUser(_.sAMAccountName), _.groups ? _.groups : ad.getGroupMembershipForUser(_.sAMAccountName),
lastLogin: _ => _.lastLogin.toISOString(),
lastLoginPrior: _ => _.lastLoginPrior.toISOString(),
sharedFolders: _ => sharedFolders: _ =>
_.groups _.groups
? _.groups ? _.groups
@ -34,11 +37,13 @@ const User = {
) )
return [] return []
return prisma.user.findOne({ return prisma.user
where: { .findOne({
sAMAccountName: _.sAMAccountName where: {
} sAMAccountName: _.sAMAccountName
}).WifiDevice() }
})
.WifiDevice()
} }
} }

View File

@ -5,8 +5,8 @@ const typeDefs = gql`
"Returns only a few fields of User" "Returns only a few fields of User"
basicUser(sAMAccountName: String!): User! @cacheControl(maxAge: 350) basicUser(sAMAccountName: String!): User! @cacheControl(maxAge: 350)
me: User! @auth @cacheControl(maxAge: 30, scope: PRIVATE) me: User! @auth
"@cacheControl(maxAge: 30, scope: PRIVATE)"
users( users(
where: UserWhereInput! where: UserWhereInput!
limit: Int = 15 limit: Int = 15
@ -45,7 +45,7 @@ const typeDefs = gql`
directive @auth(roles: [String!]) on FIELD_DEFINITION directive @auth(roles: [String!]) on FIELD_DEFINITION
"A mix between the database User and the Active Directory User" "A mix between the database User and the Active Directory User"
type User @cacheControl(maxAge: 350, scope: PRIVATE) { type User {
id: ID id: ID
wifiDevices: [WifiDevice!] wifiDevices: [WifiDevice!]

39
web/package-lock.json generated
View File

@ -9720,10 +9720,9 @@
"dev": true "dev": true
}, },
"date-fns": { "date-fns": {
"version": "1.30.1", "version": "2.16.1",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz", "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.16.1.tgz",
"integrity": "sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==", "integrity": "sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ=="
"dev": true
}, },
"de-indent": { "de-indent": {
"version": "1.0.2", "version": "1.0.2",
@ -14005,6 +14004,12 @@
"figures": "^2.0.0" "figures": "^2.0.0"
}, },
"dependencies": { "dependencies": {
"date-fns": {
"version": "1.30.1",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz",
"integrity": "sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==",
"dev": true
},
"figures": { "figures": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz",
@ -14744,7 +14749,8 @@
"moment": { "moment": {
"version": "2.29.1", "version": "2.29.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==" "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==",
"dev": true
}, },
"move-concurrently": { "move-concurrently": {
"version": "1.0.1", "version": "1.0.1",
@ -19932,6 +19938,21 @@
} }
} }
}, },
"vue-date-fns": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/vue-date-fns/-/vue-date-fns-2.0.1.tgz",
"integrity": "sha512-j2G97bVOKO0mVfFEnzCu5dQU0dgD8jLAAVU0dGRDqxZzzNXqep7d3WEGuuJ6mNOP5PM7GE+UqpKYfkL/LNmDKQ==",
"requires": {
"date-fns": "^2.0.0"
},
"dependencies": {
"date-fns": {
"version": "2.16.1",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.16.1.tgz",
"integrity": "sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ=="
}
}
},
"vue-eslint-parser": { "vue-eslint-parser": {
"version": "7.1.0", "version": "7.1.0",
"resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-7.1.0.tgz", "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-7.1.0.tgz",
@ -20088,14 +20109,6 @@
} }
} }
}, },
"vue-moment": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/vue-moment/-/vue-moment-4.1.0.tgz",
"integrity": "sha512-Gzisqpg82ItlrUyiD9d0Kfru+JorW2o4mQOH06lEDZNgxci0tv/fua1Hl0bo4DozDV2JK1r52Atn/8QVCu8qQw==",
"requires": {
"moment": "^2.19.2"
}
},
"vue-router": { "vue-router": {
"version": "3.4.6", "version": "3.4.6",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.4.6.tgz", "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.4.6.tgz",

View File

@ -11,14 +11,14 @@
"dependencies": { "dependencies": {
"@mdi/font": "^5.6.55", "@mdi/font": "^5.6.55",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"moment": "^2.29.1", "date-fns": "^2.16.1",
"qrcode.vue": "^1.7.0", "qrcode.vue": "^1.7.0",
"roboto-fontface": "*", "roboto-fontface": "*",
"validator": "^13.1.17", "validator": "^13.1.17",
"vue": "^2.6.12", "vue": "^2.6.12",
"vue-apollo": "^3.0.4", "vue-apollo": "^3.0.4",
"vue-date-fns": "^2.0.1",
"vue-json-pretty": "^1.7.0", "vue-json-pretty": "^1.7.0",
"vue-moment": "^4.1.0",
"vue-router": "^3.4.6", "vue-router": "^3.4.6",
"vue-the-mask": "^0.11.1", "vue-the-mask": "^0.11.1",
"vuetify": "^2.3.13", "vuetify": "^2.3.13",

View File

@ -34,7 +34,7 @@
> >
Visto Visto
<span class="font-weight-medium"> <span class="font-weight-medium">
{{ userPresence.wifiDevices[0].lastSeen | moment('from') }} {{ userPresence.wifiDevices[0].lastSeen | from }}
</span> </span>
</v-list-item-subtitle> </v-list-item-subtitle>
<v-list-item-subtitle v-else> On-line </v-list-item-subtitle> <v-list-item-subtitle v-else> On-line </v-list-item-subtitle>

View File

@ -69,7 +69,7 @@
</v-list-item-action> </v-list-item-action>
<v-list-item-content> <v-list-item-content>
<v-list-item-title> <v-list-item-title>
{{ wifiDevice.lastSeen | moment('LLLL') }} {{ wifiDevice.lastSeen | from }}
</v-list-item-title> </v-list-item-title>
<v-list-item-subtitle> Visto pela última vez </v-list-item-subtitle> <v-list-item-subtitle> Visto pela última vez </v-list-item-subtitle>
</v-list-item-content> </v-list-item-content>

View File

@ -6,15 +6,12 @@
<v-icon>mdi-login</v-icon> <v-icon>mdi-login</v-icon>
</v-list-item-avatar> </v-list-item-avatar>
<v-list-item-content> <v-list-item-content>
<v-list-item-title <v-list-item-title>
>Seu último login foi Seu último login foi
{{ me.lastLogin | moment('from', 'now') }}</v-list-item-title {{ me.lastLogin | from }}
> </v-list-item-title>
<v-list-item-subtitle> <v-list-item-subtitle>
{{ {{ me.lastLoginPrior | dateAndTime }}
me.lastLoginPrior
| moment('dddd, DD [de] MMMM [de] YYYY, [às] hh:mm')
}}
</v-list-item-subtitle> </v-list-item-subtitle>
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>
@ -26,10 +23,10 @@
<v-list-item-content> <v-list-item-content>
<v-list-item-title <v-list-item-title
>Você alterou sua senha >Você alterou sua senha
{{ me.pwdLastSet | moment('from', 'now') }}</v-list-item-title {{ me.pwdLastSet | from }}</v-list-item-title
> >
<v-list-item-subtitle> <v-list-item-subtitle>
{{ me.pwdLastSet | moment('dddd, DD [de] MMMM [de] YYYY') }} {{ me.pwdLastSet | dateAndTime }}
</v-list-item-subtitle> </v-list-item-subtitle>
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>

View File

@ -3,11 +3,12 @@ import App from './App.vue'
import router from './router' import router from './router'
import vuetify from './plugins/vuetify' import vuetify from './plugins/vuetify'
import './plugins/vue-moment'
import 'roboto-fontface/css/roboto/roboto-fontface.css' import 'roboto-fontface/css/roboto/roboto-fontface.css'
import '@mdi/font/css/materialdesignicons.css' import '@mdi/font/css/materialdesignicons.css'
import './scss/style.scss' import './scss/style.scss'
import './plugins/date'
import { defaultApolloProvider } from './plugins/vue-apollo' import { defaultApolloProvider } from './plugins/vue-apollo'
Vue.config.productionTip = false Vue.config.productionTip = false

13
web/src/plugins/date.js Normal file
View File

@ -0,0 +1,13 @@
import Vue from 'vue'
import { format, formatDistance, fromUnixTime } from 'date-fns'
import locale from 'date-fns/locale/pt-BR'
Vue.filter('dateAndTime', val =>
format(new Date(val), "d 'de' MMMM 'de' yyyy 'às' HH:MM", { locale })
)
Vue.filter('shortDate', val => format(val, 'dd/MM/yyyy', { locale }))
Vue.filter('from', val =>
formatDistance(new Date(val), Date.now(), { locale, addSuffix: true })
)

View File

@ -1,10 +0,0 @@
import Vue from 'vue'
import moment from 'moment'
require('moment/locale/pt-br')
import vueMoment from 'vue-moment'
Vue.use(vueMoment, {
moment
})

View File

@ -33,7 +33,7 @@
Válido até Válido até
{{ {{
tokenInfo.expiration tokenInfo.expiration
| moment('dddd, D [de] MMMM [de] YYYY [às] h:mm') | dateAndtime
}} }}
</div> </div>
</v-col> </v-col>
@ -110,7 +110,7 @@
<v-col> <v-col>
<div class="signature text-center"> <div class="signature text-center">
{{ tokenInfo.user.displayName }}, {{ tokenInfo.user.displayName }},
{{ tokenInfo.createdAt | moment('DD [de] MMMM [de] YYYY') }} {{ tokenInfo.createdAt | dateAndTime }}
</div> </div>
</v-col> </v-col>
</v-row> </v-row>

View File

@ -25,7 +25,7 @@
{{ me.extensionAttribute1 }} / {{ me.department }}<br /> {{ me.extensionAttribute1 }} / {{ me.department }}<br />
<strong>CPF:</strong> {{ me.extensionAttribute6 }}<br /> <strong>CPF:</strong> {{ me.extensionAttribute6 }}<br />
<strong>Nasc.:</strong> <strong>Nasc.:</strong>
{{ me.extensionAttribute7 | moment('DD/MM/YYYY') }}<br /> {{ me.extensionAttribute7 | shortDate }}<br />
</v-col> </v-col>
</v-row> </v-row>
<v-row> <v-row>