This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const paginate = async (model, pageSize, pageLimit, search = {}, order = [], transform) => { | |
try { | |
const limit = parseInt(pageLimit, 10) || 10; | |
const page = parseInt(pageSize, 10) || 1; | |
// create an options object | |
let options = { | |
offset: getOffset(page, limit), | |
limit: limit, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Op } from 'sequelize'; | |
import ProductModel from './product.model'; | |
/* | |
* List products | |
*/ | |
export const listProducts = async(req, res) => { | |
try { | |
// get the query params | |
const { q, page, limit, order_by, order_direction } = req.query; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from 'express'; | |
import { json, urlencoded } from 'body-parser'; | |
import { connect } from './utils/database'; | |
export const app = express(); | |
app.use(json()); | |
app.use(urlencoded({ extended: true })); | |
export const start = async () => { | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Sequelize } from 'sequelize'; | |
import { config } from '../config/local'; | |
export const sequelize = new Sequelize(config.database, config.username, config.password, { | |
host: config.host, | |
dialect: 'mysql' | |
}); | |
export const connect = async () => { | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DataTypes, Model } from 'sequelize'; | |
import { sequelize } from '../../utils/database'; | |
class ProductModel extends Model {} | |
const Product = Product.init({ | |
id: { | |
type: DataTypes.INTEGER, | |
primaryKey: true, | |
autoIncrement: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sign out the user upon button click. | |
*/ | |
const handleSignOutClick = (event) => { | |
setListDocumentsVisibility(false); | |
gapi.auth2.getAuthInstance().signOut(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Called when the signed in status changes, to update the UI | |
* appropriately. After a sign-in, the API is called. | |
*/ | |
const updateSigninStatus = (isSignedIn) => { | |
if (isSignedIn) { | |
// Set the signed in user | |
setSignedInUser(gapi.auth2.getAuthInstance().currentUser.je.Qt); | |
setIsLoadingGoogleDriveApi(false); | |
// list files if user is authenticated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Initializes the API client library and sets up sign-in state | |
* listeners. | |
*/ | |
const initClient = () => { | |
setIsLoadingGoogleDriveApi(true); | |
gapi.client | |
.init({ | |
apiKey: API_KEY, | |
clientId: CLIENT_ID, |