Skip to content

Commit

Permalink
Merge pull request #39 from AplinkosMinisterija/upcoming-fishstocking…
Browse files Browse the repository at this point in the history
…s-endpoint

Endpoint for upcoming fish stockings
  • Loading branch information
ambrazasp authored Nov 30, 2023
2 parents 112d780 + b3b44e6 commit 2c9ac6d
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"moleculer-decorators": "^1.3.0",
"moleculer-knex-filters": "github:DadPatch/moleculer-knex-filters",
"moleculer-minio": "github:zeckon/moleculer-minio",
"moleculer-postgis": "^0.2.7",
"moleculer-sentry": "^2.0.0",
"moleculer-web": "^0.10.5",
"nats": "^2.13.1",
Expand Down
123 changes: 123 additions & 0 deletions services/publishing.fishStockings.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
'use strict';

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

import PostgisMixin from 'moleculer-postgis';
import DbConnection from '../mixins/database.mixin';
import { RestrictionType, Table } from '../types';
import { FishAge } from './fishAges.service';
import { FishStockingStatus } from './fishStockings.service';
import { FishType } from './fishTypes.service';

interface Fields {
id: number;
eventTime: Date;
geom: any;
location: {
name: string;
area: number;
cadastral_id: string;
municipality: {
id: number;
name: string;
};
};
fishes: {
fish_type: FishType<never, 'id' | 'label'>;
fish_age: FishAge<never, 'id' | 'label'>;
count: number;
weight: number;
};
}

interface Populates {}

export type PublishingFishStocking<
P extends keyof Populates = never,
F extends keyof (Fields & Populates) = keyof Fields,
> = Table<Fields, Populates, P, F>;

@Service({
name: 'publishing.fishStockings',
mixins: [
DbConnection({
collection: 'publishing.fishStockings',
rest: false,
createActions: {
create: false,
update: false,
remove: false,
get: false,
createMany: false,
removeAllEntities: false,
},
}),
PostgisMixin({
srid: 3346,
}),
],
settings: {
fields: {
id: {
type: 'number',
primaryKey: true,
secure: true,
},

eventTime: {
type: 'date',
columnType: 'datetime',
},

geom: {
type: 'any',
geom: {
type: 'geom',
},
},

location: {
type: 'object',
columnType: 'json',
},

fishes: {
type: 'array',
columnType: 'json',
items: { type: 'object' },
},

status: 'string',
},

defaultPopulates: ['geom'],
},
})
export default class PublishingFishStockingsService extends moleculer.Service {
@Action({
rest: <RestSchema>{
method: 'GET',
basePath: '/public/fishStockings',
path: '/upcoming',
},
auth: RestrictionType.PUBLIC,
})
getPublicItems(ctx: Context<{ query: any }>) {
ctx.params.query = ctx.params.query || {};
if (typeof ctx.params.query === 'string') {
try {
ctx.params.query = JSON.parse(ctx.params.query);
} catch (err) {}
}

ctx.params.query.status = ctx.params.query.status || {
$in: [FishStockingStatus.ONGOING, FishStockingStatus.UPCOMING],
};

return ctx.call('publishing.fishStockings.list', {
...(ctx.params || {}),
sort: 'eventTime',
});
}
}
39 changes: 39 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,14 @@ gensync@^1.0.0-beta.2:
resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0"
integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==

geojsonjs@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/geojsonjs/-/geojsonjs-0.1.2.tgz#470a905671a50e712a39edd4cd16ed9755a2a387"
integrity sha512-ixEYX5NPi2K66eEbU6r93Dw2lkQdnfEiNuIXnRPgumzDrKp1k1xlJDN1AODA+gqvsb3r3Rz1EexmTfvjgnKPCg==
dependencies:
lodash "^4.17.21"
typescript "^4.5.5"

get-caller-file@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
Expand Down Expand Up @@ -4242,6 +4250,16 @@ moleculer-decorators@^1.3.0:
ramda "0.27.1"
ramda-adjunct "^2.35.0"

moleculer-postgis@^0.2.7:
version "0.2.7"
resolved "https://registry.yarnpkg.com/moleculer-postgis/-/moleculer-postgis-0.2.7.tgz#a3b1087e33bade1c54e18ded43facd5505b07940"
integrity sha512-JO/OPiyIfsV5u7KKBgozSA57CGAJEmuOBRTESiadjiJGDkuDWiu30h4aQ4/nzAEjVSc2aHOiDI2iU9QEQlMy+Q==
dependencies:
geojsonjs "^0.1.2"
lodash "^4.17.21"
moleculer "^0.14.31"
typescript "^4.5.5"

moleculer-repl@^0.7.3:
version "0.7.4"
resolved "https://registry.yarnpkg.com/moleculer-repl/-/moleculer-repl-0.7.4.tgz#77d3c8dd0df21fa45f3c10e78f919c58b0fcb0d5"
Expand Down Expand Up @@ -4300,6 +4318,22 @@ moleculer@^0.14.0, moleculer@^0.14.29:
node-fetch "^2.6.7"
recursive-watch "^1.1.4"

moleculer@^0.14.31:
version "0.14.32"
resolved "https://registry.yarnpkg.com/moleculer/-/moleculer-0.14.32.tgz#93abe48d79f989fe4104d56534ff40d60c91318b"
integrity sha512-N5RXKS9Z01Gl6gLkf3snLgYbzU0bLci1WNEIuy2D+cjEg7i3XEArsiFHKnmNYWF6L5DajVrT8dw9EqGgvmjmOw==
dependencies:
args "^5.0.3"
eventemitter2 "^6.4.9"
fastest-validator "^1.17.0"
glob "^7.2.0"
ipaddr.js "^2.1.0"
kleur "^4.1.5"
lodash "^4.17.21"
lru-cache "^6.0.0"
node-fetch "^2.6.7"
recursive-watch "^1.1.4"

mri@1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/mri/-/mri-1.1.4.tgz#7cb1dd1b9b40905f1fac053abe25b6720f44744a"
Expand Down Expand Up @@ -5772,6 +5806,11 @@ typescript@5.1.6:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==

typescript@^4.5.5:
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

unbox-primitive@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.2.tgz#29032021057d5e6cdbd08c5129c226dff8ed6f9e"
Expand Down

0 comments on commit 2c9ac6d

Please sign in to comment.