Implement location management

This commit is contained in:
Fredrik Adelöw
2020-05-11 16:51:54 +02:00
parent 2955884047
commit d682714249
12 changed files with 257 additions and 83 deletions
+5 -4
View File
@@ -39,13 +39,14 @@ import { PluginEnvironment } from './types';
const DEFAULT_PORT = 7000;
const PORT = parseInt(process.env.PORT ?? '', 10) || DEFAULT_PORT;
const pluginEnvironment: PluginEnvironment = {
logger: getRootLogger().child({ type: 'plugin' }),
};
async function main() {
const database = await buildDatabase(getRootLogger());
console.log(await database.select().from('locations'));
const pluginEnvironment: PluginEnvironment = {
logger: getRootLogger().child({ type: 'plugin' }),
database,
};
const app = express();
+4 -14
View File
@@ -15,22 +15,12 @@
*/
import {
AggregatorInventory,
DatabaseInventory,
createRouter,
StaticInventory,
} from '@backstage/plugin-inventory-backend';
import type { PluginEnvironment } from '../types';
export default async function ({ logger }: PluginEnvironment) {
const inventory = new AggregatorInventory();
inventory.enlist(
new StaticInventory([
{ id: 'component1' },
{ id: 'component2' },
{ id: 'component3' },
{ id: 'component4' },
]),
);
import { PluginEnvironment } from '../types';
export default async function({ logger, database }: PluginEnvironment) {
const inventory = new DatabaseInventory(database);
return await createRouter({ inventory, logger });
}
+3 -1
View File
@@ -14,8 +14,10 @@
* limitations under the License.
*/
import type { Logger } from 'winston';
import Knex from 'knex';
import { Logger } from 'winston';
export type PluginEnvironment = {
logger: Logger;
database: Knex;
};