stuff #29

Merged
PouuleT merged 1 commits from stuff into master 2020-04-16 16:00:05 +00:00
3 changed files with 16 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"database/sql"
"errors"
"fmt"
"time"
"github.com/jmoiron/sqlx"
"github.com/jmoiron/sqlx/types"
@ -25,7 +26,16 @@ const (
RETURNING *;`
deleteUserQuery = `DELETE FROM users WHERE id=:id;`
getAllUsersQuery = `SELECT * FROM users order by created_at;`
getAllUsersQuery = `
SELECT u.*, tok.last_seen
FROM users u
LEFT OUTER JOIN (
SELECT username, MAX(last_used) AS last_seen
FROM tokens GROUP BY username
) AS tok
ON u.name = tok.username
ORDER by u.created_at;
`
getPolochonUsersQuery = `SELECT * FROM users WHERE polochon_id = $1;`
)
@ -51,6 +61,7 @@ type User struct {
PolochonID sql.NullString `json:"polochon_id" db:"polochon_id"`
PolochonActivated bool `json:"polochon_activated" db:"polochon_activated"`
Polochon *Polochon `json:"polochon"`
LastSeen *time.Time `json:"last_seen" db:"last_seen"`
}
// NewPapiClient creates a new papi client for the given user

View File

@ -1,4 +1,5 @@
import React from "react";
import moment from "moment";
import PropTypes from "prop-types";
import { useSelector } from "react-redux";
@ -7,10 +8,10 @@ import { UserEdit } from "./userEdit";
export const User = ({ id }) => {
const user = useSelector((state) => state.admin.users.get(id));
const polochon = user.polochon;
const lastSeen = moment(user.last_seen, "YYYY-MM-DDTHH:mm:ss.SZ");
return (
<tr>
<td>{user.id}</td>
<td>{user.name}</td>
<td>
<span
@ -32,6 +33,7 @@ export const User = ({ id }) => {
}
></span>
</td>
<td>{lastSeen.isValid() ? lastSeen.fromNow() : "-"}</td>
<td>
<UserEdit id={id} />
</td>

View File

@ -24,13 +24,13 @@ export const UserList = () => {
<table className="table table-striped">
<thead className="table-secondary">
<tr>
<th>#</th>
<th>Name</th>
<th>Activated</th>
<th>Admin</th>
<th>Polochon URL</th>
<th>Polochon token</th>
<th>Polochon activated</th>
<th>Last seen</th>
<th>Actions</th>
</tr>
</thead>