eslint: follow new rules

This commit is contained in:
vchikalkin 2023-08-01 14:27:51 +03:00
parent 0117a4fd58
commit 3454ea9dfa
28 changed files with 136 additions and 133 deletions

View File

@ -1,7 +1,7 @@
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
describe('AppController', () => {
let appController: AppController;

View File

@ -1,5 +1,5 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { Controller, Get } from '@nestjs/common';
@Controller()
export class AppController {

View File

@ -1,14 +1,16 @@
import { Global, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
import { UsersModule } from './users/users.module';
import { LdapModule } from './ldap/ldap.module';
import { UsersModule } from './users/users.module';
import { Global, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
@Global()
@Module({
controllers: [AppController],
exports: [JwtModule],
imports: [
ConfigModule.forRoot({
isGlobal: true,
@ -23,8 +25,7 @@ import { LdapModule } from './ldap/ldap.module';
UsersModule,
LdapModule,
],
controllers: [AppController],
providers: [AppService],
exports: [JwtModule],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class AppModule {}

View File

@ -1,7 +1,7 @@
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
describe('AuthController', () => {
let controller: AuthController;

View File

@ -1,10 +1,10 @@
/* eslint-disable class-methods-use-this */
/* eslint-disable import/no-extraneous-dependencies */
import { Body, Controller, Get, HttpException, HttpStatus, Post, Req, Res } from '@nestjs/common';
import { FastifyReply, FastifyRequest } from 'fastify';
import { AuthService } from './auth.service';
import { COOKIE_TOKEN_NAME } from './lib/constants';
import { Credentials } from './types/request';
import { Body, Controller, Get, HttpException, HttpStatus, Post, Req, Res } from '@nestjs/common';
import { FastifyReply, FastifyRequest } from 'fastify';
@Controller()
export class AuthController {

View File

@ -1,12 +1,13 @@
import { Module } from '@nestjs/common';
import { LdapModule } from '../ldap/ldap.module';
import { UsersModule } from '../users/users.module';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { Module } from '@nestjs/common';
@Module({
imports: [UsersModule, LdapModule],
controllers: [AuthController],
imports: [UsersModule, LdapModule],
providers: [AuthService],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class AuthModule {}

View File

@ -1,6 +1,6 @@
import { AuthService } from './auth.service';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import { AuthService } from './auth.service';
describe('AuthService', () => {
let service: AuthService;

View File

@ -1,8 +1,8 @@
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { LdapService } from '../ldap/ldap.service';
import { UsersCache } from '../users/users.cache';
import type { DecodedToken, TokenPayload } from './types/jwt';
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
@Injectable()
export class AuthService {
@ -19,8 +19,8 @@ export class AuthService {
await this.usersCache.addUser(username, user);
const payload: TokenPayload = {
username,
domain: process.env.LDAP_DOMAIN,
username,
};
return this.jwtService.sign(payload);

View File

@ -1,8 +1,9 @@
import { Module } from '@nestjs/common';
import { LdapService } from './ldap.service';
import { Module } from '@nestjs/common';
@Module({
providers: [LdapService],
exports: [LdapService],
providers: [LdapService],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class LdapModule {}

View File

@ -1,6 +1,6 @@
import { LdapService } from './ldap.service';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import { LdapService } from './ldap.service';
describe('LdapService', () => {
let service: LdapService;

View File

@ -1,22 +1,22 @@
import type { User } from '../types/user';
import type { LdapUser } from './types/user';
import { Injectable } from '@nestjs/common';
import type { AuthenticationOptions } from 'ldap-authentication';
import { authenticate } from 'ldap-authentication';
import type { User } from '../types/user';
import type { LdapUser } from './types/user';
@Injectable()
export class LdapService {
async authenticate(login: string, password?: string) {
const options: AuthenticationOptions = {
adminDn: process.env.LDAP_BIND_DN,
adminPassword: process.env.LDAP_BIND_CREDENTIALS,
ldapOpts: {
url: process.env.LDAP_URL,
},
adminDn: process.env.LDAP_BIND_DN,
adminPassword: process.env.LDAP_BIND_CREDENTIALS,
userSearchBase: process.env.LDAP_BASE,
usernameAttribute: process.env.LDAP_ATTRIBUTE,
username: login,
userPassword: password,
userSearchBase: process.env.LDAP_BASE,
username: login,
usernameAttribute: process.env.LDAP_ATTRIBUTE,
verifyUserExists: password === undefined,
};
@ -29,13 +29,13 @@ export class LdapService {
}: LdapUser = await authenticate(options);
const user: User = {
username,
domain: process.env.LDAP_DOMAIN,
displayName,
department,
position: title,
mail,
displayName,
domain: process.env.LDAP_DOMAIN,
domainName: `${process.env.LDAP_DOMAIN}\\${username}`,
mail,
position: title,
username,
};
return user;

View File

@ -1,63 +1,63 @@
export type LdapUser = {
dn: string;
controls: any[];
objectClass: string[];
cn: string;
sn: string;
c: string;
title: string;
physicalDeliveryOfficeName: string;
givenName: string;
distinguishedName: string;
instanceType: string;
whenCreated: string;
whenChanged: string;
displayName: string;
uSNCreated: string;
memberOf: string[];
uSNChanged: string;
co: string;
department: string;
proxyAddresses: string[];
name: string;
objectGUID: string;
userAccountControl: string;
badPwdCount: string;
codePage: string;
countryCode: string;
employeeID: string;
accountExpires: string;
badPasswordTime: string;
badPwdCount: string;
c: string;
cn: string;
co: string;
codePage: string;
controls: unknown[];
countryCode: string;
dSCorePropagationData: string[];
department: string;
displayName: string;
distinguishedName: string;
dn: string;
employeeID: string;
extensionAttribute1: string;
extensionAttribute13: string;
extensionAttribute2: string;
givenName: string;
instanceType: string;
lastLogoff: string;
lastLogon: string;
pwdLastSet: string;
primaryGroupID: string;
objectSid: string;
accountExpires: string;
lastLogonTimestamp: string;
legacyExchangeDN: string;
lockoutTime: string;
logonCount: string;
'mS-DS-ConsistencyGuid': string;
mail: string;
mailNickname: string;
memberOf: string[];
middleName: string;
'msDS-KeyCredentialLink': string;
msExchMailboxGuid: string;
msExchPoliciesIncluded: string[];
msExchRecipientDisplayType: string;
msExchRecipientTypeDetails: string;
msExchRemoteRecipientType: string;
msExchUMDtmfMap: string[];
msExchVersion: string;
name: string;
objectCategory: string;
objectClass: string[];
objectGUID: string;
objectSid: string;
physicalDeliveryOfficeName: string;
preferredLanguage: string;
primaryGroupID: string;
proxyAddresses: string[];
pwdLastSet: string;
sAMAccountName: string;
sAMAccountType: string;
showInAddressBook: string[];
legacyExchangeDN: string;
userPrincipalName: string;
lockoutTime: string;
objectCategory: string;
dSCorePropagationData: string[];
'mS-DS-ConsistencyGuid': string;
lastLogonTimestamp: string;
'msDS-KeyCredentialLink': string;
mail: string;
middleName: string;
preferredLanguage: string;
extensionAttribute2: string;
msExchVersion: string;
msExchRecipientDisplayType: string;
msExchRecipientTypeDetails: string;
extensionAttribute1: string;
msExchMailboxGuid: string;
sn: string;
targetAddress: string;
msExchPoliciesIncluded: string[];
extensionAttribute13: string;
mailNickname: string;
msExchRemoteRecipientType: string;
msExchUMDtmfMap: string[];
title: string;
uSNChanged: string;
uSNCreated: string;
userAccountControl: string;
userPrincipalName: string;
whenChanged: string;
whenCreated: string;
};

View File

@ -1,9 +1,9 @@
/* eslint-disable unicorn/prefer-top-level-await */
import fastifyCookie from '@fastify/cookie';
import { AppModule } from './app.module';
import { fastifyCookie } from '@fastify/cookie';
import { NestFactory } from '@nestjs/core';
import type { NestFastifyApplication } from '@nestjs/platform-fastify';
import { FastifyAdapter } from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(

View File

@ -1,9 +1,9 @@
export type User = {
displayName: string;
username: string;
department: string;
position: string;
mail: string;
displayName: string;
domain: string;
domainName: string;
mail: string;
position: string;
username: string;
};

View File

@ -1,14 +1,12 @@
import type { User } from '../types/user';
import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
import { Cache } from 'cache-manager';
import type { User } from '../types/user';
@Injectable()
export class UsersCache {
constructor(@Inject(CACHE_MANAGER) private readonly cacheManager: Cache) {}
async getUser(username: string) {
const user = (await this.cacheManager.get(username)) as User;
return user;
return (await this.cacheManager.get(username)) as User;
}
async addUser(username: string, user: User) {

View File

@ -1,7 +1,7 @@
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
describe('UsersController', () => {
let controller: UsersController;

View File

@ -1,9 +1,9 @@
/* eslint-disable class-methods-use-this */
/* eslint-disable import/no-extraneous-dependencies */
import { Controller, Get, Req, Res } from '@nestjs/common';
import { FastifyReply, FastifyRequest } from 'fastify';
import { COOKIE_TOKEN_NAME } from '../auth/lib/constants';
import { UsersService } from './users.service';
import { Controller, Get, Req, Res } from '@nestjs/common';
import { FastifyReply, FastifyRequest } from 'fastify';
@Controller()
export class UsersController {

View File

@ -1,23 +1,24 @@
import { CacheModule, Module } from '@nestjs/common';
import * as redisStore from 'cache-manager-ioredis';
import type { RedisOptions } from 'ioredis';
import { LdapModule } from '../ldap/ldap.module';
import { UsersCache } from './users.cache';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';
import { CacheModule, Module } from '@nestjs/common';
import * as redisStore from 'cache-manager-ioredis';
import type { RedisOptions } from 'ioredis';
@Module({
controllers: [UsersController],
exports: [UsersCache],
imports: [
CacheModule.register<RedisOptions>({
store: redisStore,
host: process.env.REDIS_HOST,
port: Number.parseInt(process.env.REDIS_PORT, 10) || 6379,
store: redisStore,
ttl: Number.parseInt(process.env.CACHE_TTL, 10),
}),
LdapModule,
],
controllers: [UsersController],
providers: [UsersService, UsersCache],
exports: [UsersCache],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class UsersModule {}

View File

@ -1,6 +1,6 @@
import { UsersService } from './users.service';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import { UsersService } from './users.service';
describe('UsersService', () => {
let service: UsersService;

View File

@ -1,8 +1,8 @@
import type { DecodedToken } from '../auth/types/jwt';
import { LdapService } from '../ldap/ldap.service';
import { UsersCache } from './users.cache';
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { LdapService } from '../ldap/ldap.service';
import type { DecodedToken } from '../auth/types/jwt';
import { UsersCache } from './users.cache';
@Injectable()
export class UsersService {

View File

@ -1,8 +1,8 @@
import { AppModule } from '../src/app.module';
import type { INestApplication } from '@nestjs/common';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import type { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from '../src/app.module';
describe('AppController (e2e)', () => {
let app: INestApplication;
@ -16,8 +16,5 @@ describe('AppController (e2e)', () => {
await app.init();
});
it('/ (GET)', () => request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!'));
it('/ (GET)', () => request(app.getHttpServer()).get('/').expect(200).expect('Hello World!'));
});

View File

@ -1,18 +1,18 @@
import Input from 'elements/Input';
import Button from 'elements/Button';
import styles from './Form.module.scss';
import { H3 } from 'elements/H';
import { useRouter } from 'next/router';
import Error from 'elements/Error';
import getConfig from 'next/config';
import axios from 'axios';
import Button from 'elements/Button';
import Error from 'elements/Error';
import { H3 } from 'elements/H';
import Input from 'elements/Input';
import getConfig from 'next/config';
import { useRouter } from 'next/router';
import { useState } from 'react';
const { publicRuntimeConfig: config } = getConfig();
export default function Form() {
const router = useRouter();
const [hasError, setError] = useState(false);
const [hasError, setHasError] = useState(false);
const error = hasError ? <Error>Неверный логин или пароль</Error> : null;
return (
@ -31,7 +31,7 @@ export default function Form() {
router.reload();
})
.catch(() => {
setError(true);
setHasError(true);
});
}}
>

View File

@ -1,6 +1,6 @@
import Form from './Form';
import Logo from 'elements/Logo';
import styles from './Login.module.scss';
import Logo from 'elements/Logo';
export default function Login() {
return (

View File

@ -4,7 +4,7 @@ type ButtonProps = JSX.IntrinsicElements['button'];
export default function Button({ children, ...props }: ButtonProps) {
return (
<button className={styles.btn} {...props}>
<button type="button" className={styles.btn} {...props}>
{children}
</button>
);

View File

@ -1,5 +1,5 @@
import logo from 'public/assets/images/logo-primary.svg';
import Image from 'next/image';
import logo from 'public/assets/images/logo-primary.svg';
export default function Logo() {
return <Image src={logo} alt="logo" width={154} />;

View File

@ -1,9 +1,10 @@
import type { AppProps } from 'next/app';
/* eslint-disable react/no-unknown-property */
import 'normalize.css';
import Head from 'next/head';
import '@fontsource/montserrat/400.css';
import '@fontsource/montserrat/600.css';
import '@fontsource/montserrat/700.css';
import type { AppProps } from 'next/app';
import Head from 'next/head';
export default function App({ Component, pageProps }: AppProps) {
return (

View File

@ -3,14 +3,14 @@
"version": "0.0.0",
"private": true,
"workspaces": [
"apps/*",
"packages/*"
"apps/*"
],
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev --parallel",
"lint": "turbo run lint",
"lint:fix": "turbo run lint:fix",
"clean": "turbo run clean",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
"devDependencies": {
@ -22,4 +22,4 @@
},
"dependencies": {},
"packageManager": "yarn@1.22.19"
}
}

View File

@ -17,6 +17,9 @@
"dev": {
"cache": false,
"persistent": true
},
"clean": {
"cache": false
}
}
}