Skip to content

thomascsd/stools

Repository files navigation

stools

Table of Contents

About

My Swiss knife

Getting Started

Flowing features;

Deep dependency

stools use typedi as dependency injection, and async-airtable as access AirTable API.

npm install typedi reflect-metadata asyncairtable

Installing

npm install @thomascsd/stools

Usage

import { Service, Container } from 'typedi';
import { DataService, BaseModel, API_KEY_TOKEN } from '@thomascsd/stools';

Container.set(API_KEY_TOKEN, process.env.<your api key>);

const BASE_ID = '<your base id>';

export class Contact extends BaseModel {
  name: string;
  email: string;
  mobile: string;
}

@Service()
export class ContactService {
  constructor(private db: DataService) {}

  async getContacts(): Promise<Contact[]> {
    return await this.db.getDatas<Contact>(BASE_ID, '<your table name of AirTable>');
  }

  async saveContact(contact: Contact) {
    return await this.db.saveData<Contact>(BASE_ID, '<your table name of AirTable>', contact);
  }

  async updateContact(contact: Contact) {
    return await this.db.updateData<Contact>(BASE_ID, '<your table name of AirTable>', contact);
  }
}