Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

36 paruosti viesos statistikos atidavima pagal uetk kadastro objekta #38

13 changes: 7 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ AUTH_API_KEY=
FREELANCER_GROUP_ID=
AUTH_AAD_GROUP_ID=

MINIO_ENDPOINT="localhost"
MINIO_PORT=9000
MINIO_ENDPOINT=localhost
MINIO_PUBLIC_URL=http://localhost:9140
MINIO_PORT=9140
MINIO_USESSL=false
MINIO_ACCESSKEY="minioadmin"
MINIO_SECRETKEY="minioadmin"
MINIO_BUCKET="zuvinimas"
MINIO_ACCESSKEY=minioadmin
MINIO_SECRETKEY=minioadmin
MINIO_BUCKET=zuvinimas

REDIS_CONNECTION=redis://localhost:6379
REDIS_CONNECTION=redis://localhost:6141

GEO_SERVER=
URL=http://zuvinimas.local
Expand Down
12 changes: 7 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.5'
version: "3.5"

services:
postgres:
Expand All @@ -13,27 +13,29 @@ services:
POSTGRES_DB: zuvinimas
TZ: 'Etc/GMT'
PGTZ: 'Etc/GMT'

redis:
image: redis:latest
networks:
- internal
ports:
- 6581:6379

- 6141:6379
minio:
image: minio/minio:latest
ports:
- 9030:9000
- 9031:9001
- 9140:9000
- 9141:9001
networks:
- internal
environment:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
command: server --console-address :9001 /data


networks:
internal:


volumes:
data:
13 changes: 13 additions & 0 deletions services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ export enum AuthUserRole {
settings: {
port: process.env.PORT || 3000,
path: '/zuvinimasnew',

// Global CORS settings for all routes
cors: {
// Configures the Access-Control-Allow-Origin CORS header.
origin: '*',
// Configures the Access-Control-Allow-Methods CORS header.
methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'DELETE'],
// Configures the Access-Control-Allow-Headers CORS header.
allowedHeaders: '*',
// Configures the Access-Control-Max-Age CORS header.
maxAge: 3600,
},

routes: [
{
path: '',
Expand Down
4 changes: 3 additions & 1 deletion services/fishBatches.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Table,
} from '../types';
import { FishAge } from './fishAges.service';
import { FishStocking } from './fishStockings.service';
import { FishType } from './fishTypes.service';

interface Fields extends CommonFields {
Expand All @@ -28,8 +29,9 @@ interface Fields extends CommonFields {
}

interface Populates extends CommonPopulates {
fishTypes: FishType;
fishType: FishType;
fishAge: FishAge;
fishStocking: FishStocking;
}

export type FishBatch<
Expand Down
87 changes: 86 additions & 1 deletion services/fishStockings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { AuthUserRole, UserAuthMeta } from './api.service';
// import ExcelJS from 'exceljs';
import { isEmpty, map } from 'lodash';
import moleculer, { Context } from 'moleculer';
import moleculer, { Context, RestSchema } from 'moleculer';

import { DbContextParameters } from 'moleculer-db';
import ApiGateway from 'moleculer-web';
Expand Down Expand Up @@ -747,6 +747,91 @@ export default class FishStockingsService extends moleculer.Service {
return Number(response.rows[0].sum);
}

@Action({
rest: <RestSchema>{
method: 'GET',
basePath: '/public',
path: '/uetk/statistics',
},
params: {
date: [
{
type: 'string',
optional: true,
},
{
type: 'object',
optional: true,
},
],
fishType: {
type: 'number',
convert: true,
optional: true,
},
},
auth: RestrictionType.PUBLIC,
})
async getStatisticsForUETK(ctx: Context<{ date: any; fishType: number }>) {
const { fishType, date } = ctx.params;
const query: any = { reviewAmount: { $exists: true } };

if (fishType) {
query.fishType = fishType;
}

if (date) {
query.createdAt = date;
try {
query.createdAt = JSON.parse(date);
} catch (err) {}
}

const fishBatches: FishBatch<'fishStocking' | 'fishType'>[] = await ctx.call(
'fishBatches.find',
{
query,
populate: ['fishStocking', 'fishType'],
},
);

return Object.values(
fishBatches.reduce((groupedFishBatch, fishBatch) => {
const cadastralId = fishBatch?.fishStocking?.location?.cadastral_id;
const fishTypeId = fishBatch?.fishType?.id;
if (!cadastralId) return groupedFishBatch;

groupedFishBatch[cadastralId] = groupedFishBatch[cadastralId] || {
count: 0,
cadastralId: cadastralId,
};

groupedFishBatch[cadastralId].count += fishBatch.reviewAmount;

groupedFishBatch[cadastralId][fishTypeId] = groupedFishBatch[cadastralId][fishTypeId] || {
count: 0,
fishType: { id: fishTypeId, label: fishBatch?.fishType?.label },
};

groupedFishBatch[cadastralId][fishTypeId].count += fishBatch.reviewAmount;

return groupedFishBatch;
}, {} as any),
).reduce(
(
groupedFishBatch: { [key: string]: any },
currentGroupedFishBatch: { [key: string]: any },
) => {
const { cadastralId, count, ...rest } = currentGroupedFishBatch;

groupedFishBatch[cadastralId] = { count, byFishes: Object.values(rest) };

return groupedFishBatch;
},
{},
);
}

@Action({
rest: 'GET /export',
})
Expand Down
19 changes: 17 additions & 2 deletions services/fishTypes.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import moleculer from 'moleculer';
import { Method, Service } from 'moleculer-decorators';
import moleculer, { Context, RestSchema } from 'moleculer';
import { Action, Method, Service } from 'moleculer-decorators';

import DbConnection from '../mixins/database.mixin';
import {
Expand Down Expand Up @@ -64,6 +64,21 @@ export type FishType<
},
})
export default class FishTypesService extends moleculer.Service {
@Action({
rest: <RestSchema>{
method: 'GET',
basePath: '/public/fishTypes',
path: '/',
},
auth: RestrictionType.PUBLIC,
})
getPublicItems(ctx: Context) {
return this.findEntities(ctx, {
fields: ['id', 'label'],
sort: 'label',
});
}

@Method
async seedDB() {
await this.createEntities(null, [
Expand Down
Loading
Loading