mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
refactor: add missing tokenUserSchema fields (#1742)
This commit is contained in:
parent
ab75d4085e
commit
e013a72ddd
@ -1,15 +1,15 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`tokenUserSchema empty 1`] = `
|
||||
exports[`tokenUserSchema 1`] = `
|
||||
Object {
|
||||
"data": Object {},
|
||||
"errors": Array [
|
||||
Object {
|
||||
"instancePath": "",
|
||||
"keyword": "required",
|
||||
"message": "must have required property 'createdBy'",
|
||||
"message": "must have required property 'id'",
|
||||
"params": Object {
|
||||
"missingProperty": "createdBy",
|
||||
"missingProperty": "id",
|
||||
},
|
||||
"schemaPath": "#/required",
|
||||
},
|
||||
|
@ -3,10 +3,13 @@ import { TokenUserSchema } from './token-user-schema';
|
||||
|
||||
test('tokenUserSchema', () => {
|
||||
const data: TokenUserSchema = {
|
||||
id: 0,
|
||||
name: '',
|
||||
email: '',
|
||||
createdBy: '',
|
||||
token: '',
|
||||
role: {
|
||||
id: 1,
|
||||
id: 0,
|
||||
description: '',
|
||||
name: '',
|
||||
type: '',
|
||||
@ -16,9 +19,7 @@ test('tokenUserSchema', () => {
|
||||
expect(
|
||||
validateSchema('#/components/schemas/tokenUserSchema', data),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
test('tokenUserSchema empty', () => {
|
||||
expect(
|
||||
validateSchema('#/components/schemas/tokenUserSchema', {}),
|
||||
).toMatchSnapshot();
|
||||
|
@ -5,14 +5,24 @@ export const tokenUserSchema = {
|
||||
$id: '#/components/schemas/tokenUserSchema',
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
required: ['createdBy', 'token', 'role'],
|
||||
required: ['id', 'name', 'email', 'token', 'createdBy', 'role'],
|
||||
properties: {
|
||||
createdBy: {
|
||||
id: {
|
||||
type: 'number',
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
},
|
||||
email: {
|
||||
type: 'string',
|
||||
},
|
||||
token: {
|
||||
type: 'string',
|
||||
},
|
||||
createdBy: {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
},
|
||||
role: {
|
||||
$ref: '#/components/schemas/roleSchema',
|
||||
},
|
||||
|
@ -27,6 +27,7 @@ import DisabledError from '../error/disabled-error';
|
||||
import PasswordMismatch from '../error/password-mismatch';
|
||||
import BadDataError from '../error/bad-data-error';
|
||||
import { isDefined } from '../util/isDefined';
|
||||
import { TokenUserSchema } from '../openapi/spec/token-user-schema';
|
||||
|
||||
const systemUser = new User({ id: -1, username: 'system' });
|
||||
|
||||
@ -56,19 +57,6 @@ interface IUserWithRole extends IUser {
|
||||
rootRole: number;
|
||||
}
|
||||
|
||||
interface IRoleDescription {
|
||||
id: number;
|
||||
description: string;
|
||||
name: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface ITokenUser extends IUpdateUser {
|
||||
createdBy: string;
|
||||
token: string;
|
||||
role: IRoleDescription;
|
||||
}
|
||||
|
||||
const saltRounds = 10;
|
||||
|
||||
class UserService {
|
||||
@ -362,7 +350,7 @@ class UserService {
|
||||
return this.store.setPasswordHash(userId, passwordHash);
|
||||
}
|
||||
|
||||
async getUserForToken(token: string): Promise<ITokenUser> {
|
||||
async getUserForToken(token: string): Promise<TokenUserSchema> {
|
||||
const { createdBy, userId } = await this.resetTokenService.isValid(
|
||||
token,
|
||||
);
|
||||
|
@ -1502,6 +1502,16 @@ Object {
|
||||
"additionalProperties": false,
|
||||
"properties": Object {
|
||||
"createdBy": Object {
|
||||
"nullable": true,
|
||||
"type": "string",
|
||||
},
|
||||
"email": Object {
|
||||
"type": "string",
|
||||
},
|
||||
"id": Object {
|
||||
"type": "number",
|
||||
},
|
||||
"name": Object {
|
||||
"type": "string",
|
||||
},
|
||||
"role": Object {
|
||||
@ -1512,8 +1522,11 @@ Object {
|
||||
},
|
||||
},
|
||||
"required": Array [
|
||||
"createdBy",
|
||||
"id",
|
||||
"name",
|
||||
"email",
|
||||
"token",
|
||||
"createdBy",
|
||||
"role",
|
||||
],
|
||||
"type": "object",
|
||||
|
Loading…
Reference in New Issue
Block a user