Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
476 changes: 473 additions & 3 deletions backend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"pg": "^8.14.1",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"sharp": "^0.34.2",
"typeorm": "^0.3.20",
"uuid": "^11.1.0",
"winston": "^3.17.0"
Expand Down
4 changes: 4 additions & 0 deletions backend/src/base/location/location.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TreeParent,
} from 'typeorm';
import { DeviceEntity } from '../../inventory/device/device.entity';
import { ConsumableLocationEntity } from '../../inventory/consumable/consumable-location.entity';

export enum LocationType {
NONE = 0, // Keine Angabe
Expand Down Expand Up @@ -57,4 +58,7 @@ export class LocationEntity {

@OneToMany(() => DeviceEntity, (x) => x.location)
devices: DeviceEntity[];

@OneToMany(() => ConsumableLocationEntity, (x) => x.location)
consumableLocations: ConsumableLocationEntity[];
}
1 change: 1 addition & 0 deletions backend/src/base/location/location.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
imports: [TypeOrmModule.forFeature([LocationEntity])],
controllers: [LocationController],
providers: [LocationService, LocationDbService],
exports: [LocationDbService],
})
export class LocationModule {}
22 changes: 22 additions & 0 deletions backend/src/core/auth/role/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ export class Role {
[Role.LocationView],
);

public static readonly ConsumableGroupView = new Role(
'consumable-group.view',
'Verbrauchsgüter-Gruppe ansehen',
);
public static readonly ConsumableGroupManage = new Role(
'consumable-group.manage',
'Verbrauchsgüter-Gruppe verwalten',
[Role.ConsumableGroupView],
);
public static readonly ConsumableView = new Role(
'consumable.view',
'Verbrauchsgüter ansehen',
[Role.ConsumableGroupView, Role.LocationView],
);
public static readonly ConsumableManage = new Role(
'consumable.manage',
'Verbrauchsgüter verwalten',
[Role.ConsumableView],
);

public static readonly UserView = new Role('user.view', 'Benutzer ansehen');
public static readonly UserManage = new Role(
'user.manage',
Expand All @@ -58,6 +78,8 @@ export class Role {
Role.DeviceTypeManage,
Role.DeviceGroupManage,
Role.DeviceManage,
Role.ConsumableGroupManage,
Role.ConsumableManage,
]);

public name: string;
Expand Down
47 changes: 45 additions & 2 deletions backend/src/core/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import {
validateSync,
} from 'class-validator';
import { Logger } from '@nestjs/common';
import * as process from 'node:process';

export enum ConfigKey {
App = 'APP',
Db = 'DB',
Minio = 'MINIO',
Keycloak = 'KEYCLOAK',
Amqp = 'AMQP',
}

const AppConfig = registerAs(ConfigKey.App, () => ({
Expand All @@ -30,14 +32,23 @@ const DbConfig = registerAs(ConfigKey.Db, () => ({
database: process.env.DATABASE,
}));

const AmqpConfig = registerAs(ConfigKey.Amqp, () => ({
host: process.env.AMQP_HOST,
vhost: process.env.AMQP_VHOST,
port: Number(process.env.AMQP_PORT),
username: process.env.AMQP_USERNAME,
password: process.env.AMQP_PASSWORD,
queueFileChange: process.env.AMQP_QUEUE_FILE_CHANGE,
}));

const MinioConfig = registerAs(ConfigKey.Minio, () => ({
host: process.env.MINIO_HOST,
port: Number(process.env.MINIO_PORT),
useSsl: process.env.MINIO_USE_SSL === 'true',
accessKey: process.env.MINIO_ACCESS_KEY,
secretKey: process.env.MINIO_SECRET_KEY,
uploadExpiry: process.env.MINIO_UPLOAD_EXPIRY,
downloadExpiry: process.env.MINIO_DOWNLOAD_EXPIRY,
uploadExpiry: Number(process.env.MINIO_UPLOAD_EXPIRY),
downloadExpiry: Number(process.env.MINIO_DOWNLOAD_EXPIRY),
bucketName: process.env.MINIO_BUCKET_NAME,
}));

Expand All @@ -55,6 +66,7 @@ export const configurations = [
DbConfig,
MinioConfig,
KeycloakConfig,
AmqpConfig,
];

class EnvironmentVariables {
Expand Down Expand Up @@ -161,6 +173,37 @@ class EnvironmentVariables {
@IsString()
@MinLength(1)
KEYCLOAK_ISSUER: string;

/* AMQP CONFIG */
@IsDefined()
@IsString()
@MinLength(1)
AMQP_HOST: string;

@IsDefined()
@IsString()
@MinLength(1)
AMQP_VHOST: string;

@IsDefined()
@IsNumberString()
@MinLength(1)
AMQP_PORT: string;

@IsDefined()
@IsString()
@MinLength(1)
AMQP_USERNAME: string;

@IsDefined()
@IsString()
@MinLength(1)
AMQP_PASSWORD: string;

@IsDefined()
@IsString()
@MinLength(1)
AMQP_QUEUE_FILE_CHANGE: string;
}

export function validateConfig(configuration: Record<string, unknown>) {
Expand Down
25 changes: 23 additions & 2 deletions backend/src/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { ConfigModule, ConfigService } from '@nestjs/config';
import { configurations, validateConfig } from './configuration';
import { StartupService } from './services/startup.service';
import { MinioService } from './services/minio.service';
import { MinioService } from './services/storage/minio.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { KeycloakService } from './services/keycloak.service';
import { HttpModule } from '@nestjs/axios';
Expand All @@ -28,6 +28,14 @@ import { LoggerContextMiddleware } from './middleware/logger-context.middleware'
import { DeviceTypeEntity } from '../inventory/device-type/device-type.entity';
import { DeviceGroupEntity } from '../inventory/device-group/device-group.entity';
import { DeviceEntity } from '../inventory/device/device.entity';
import { ConsumableEntity } from '../inventory/consumable/consumable.entity';
import { ConsumableGroupEntity } from '../inventory/consumable-group/consumable-group.entity';
import { ConsumableLocationEntity } from '../inventory/consumable/consumable-location.entity';
import { AmqpService } from './services/amqp.service';
import { MinioListenerService } from './services/storage/minio-listener.service';
import { ImageService } from './services/storage/image.service';
import { DeviceImageEntity } from '../inventory/device/device-image.entity';
import { InventoryModule } from '../inventory/inventory.module';

@Module({
imports: [
Expand Down Expand Up @@ -61,6 +69,10 @@ import { DeviceEntity } from '../inventory/device/device.entity';
DeviceTypeEntity,
DeviceGroupEntity,
DeviceEntity,
ConsumableEntity,
ConsumableGroupEntity,
ConsumableLocationEntity,
DeviceImageEntity,
],
extra: {
connectionLimit: 10,
Expand All @@ -71,6 +83,7 @@ import { DeviceEntity } from '../inventory/device/device.entity';
// migrationsRun: true,
}),
}),
InventoryModule,
],
providers: [
StartupService,
Expand All @@ -83,8 +96,16 @@ import { DeviceEntity } from '../inventory/device/device.entity';
RequestContextService,
AppLoggerService,
LoggerContextMiddleware,
AmqpService,
MinioListenerService,
ImageService,
],
exports: [
MinioService,
KeycloakService,
LoggerContextMiddleware,
AmqpService,
],
exports: [MinioService, KeycloakService, LoggerContextMiddleware],
controllers: [UserController, GroupController],
})
@Global()
Expand Down
18 changes: 18 additions & 0 deletions backend/src/core/services/amqp.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AmqpService } from './amqp.service';

describe('AmqpService', () => {
let service: AmqpService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AmqpService],
}).compile();

service = module.get<AmqpService>(AmqpService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
Loading