Skip to content

Instantly share code, notes, and snippets.

View anteAdamovic's full-sized avatar
🏠
Working from home

Ante Adamovic anteAdamovic

🏠
Working from home
View GitHub Profile
// router
router.post(
'/sms',
auth,
awaitHandler(async (req, res) => {
const user = await UsersController.getUserById(req.user._id);
const mobileNumber = req.body.mobileNumber;
await SMSService.onSMSShare(mobileNumber, user);
Most of my projects are considered private and spread accross multiple github/bitbucket/gitlab accounts so I can't share them as a whole but I can share some of the standalone files (controllers, services, components, etc).
I understand some people might be suspicious of the code ownership but I guarantee that all (or at least the large majority) of the code in these examples were written personally by me.
Some of my latest work (9/6/2019):
This feature allows sharing of referral codes via sms (supports other forms such as copy, facebook, twitter, email)
but I don't consider them good of a reference ( nothing special ). SMS sending was implemented using Twilio and
proved very confusing mostly due to very little documentation and technical support from their side (requires
configuration on the client before api can be used).
public static async addLead(lead: ILead) {
if (await ValidationService.validate(lead, ["name", "surname", "company"]) && await ValidationService.checkIfLeadExists(lead, ["name", "surname", "company"], Lead)) {
lead.lastUpdate = new Date().toISOString();
// Create new lead
const createdLead: ILead = await Lead.create(lead);
// Get company from lead
const populatedLead: ILead = await Lead.findById(createdLead._id).populate('company').exec();
// Generate emails
createdLead.emails = await EmailService.generateEmails(lead, <ICompany>populatedLead.company);
// Add emails
app.use(async (req, res, next) => {
if (req.url === '/user/login' || req.url === '/user/register' || req.url === '/user/register-fb') {
next();
} else {
try {
const accessToken = req.headers['access-token'];
if (accessToken) {
const user = await User.findOne({ accessToken });
import { Response, Request } from 'express';
import { NextFunction } from 'connect';
import { FieldValidationError, DuplicateKeyError } from './validation.errors';
/**
* Error handler for routes
* @param callback : `any` - callback(req, res) which calls metohod from service and sends a responose
*/
export function errorHandler(callback: any) {
return async (req: Request, res: Response, next: NextFunction) => {
import { CompanyService } from './../../services/company/company.service';
import express, { Router, Request, Response } from "express";
import { errorHandler } from "../../errors/error.handler";
import { ICompany } from '../../models';
import { ServiceResponse } from '../../models/service.response.model';
export const companyRouter: Router = express.Router();
companyRouter.get("", errorHandler(async (req: Request, res: Response) => {
const response: ServiceResponse = await CompanyService.getCompanies();
{
"data": {
"emails": [{
"_id": "5d59d54ecf67de14d4252d63",
"address": "david@setter.com",
"validationTimestamp": "2019-08-18T22:46:38.477Z",
"valid": true,
"__v": 0
}, {
"_id": "5d59d550cf67de14d4252d66",
const people = [
{
name: 'Ante',
age: 25,
knownLanguages: [
{
name: 'HTML',
platform: 'browser',
category: 'web'
},
{
"itemId": 22210456,
"parentItemId": 22210456,
"name": "Tyson® Premium Chunk White Chicken Breast, 12.5 oz. (Twin Pack)",
"salePrice": 4.98,
"upc": "023700028877",
"categoryPath": "Food/Meal Solutions, Grains & Pasta/Canned Goods/Meat & Poultry",
"shortDescription": "Simplify lunch time with Tyson&reg; Premium Chunk White Chicken Breast. Premium white meat chicken is lightly seasoned and cooked to perfection, cut into chunks, and canned in water for the convenience of ready-to-eat chicken anytime. With 13 grams of protein per serving, our chicken is juicy, flavorful, and 98% fat-free. Simply mix drained chicken with mayonnaise and sweet relish, then serve with crackers for a quick and simple lunch. Includes two 12.5 oz. cans. Everything seems to turn out a whole lot better when you just keep it simple. No nonsense. Just stick to the good stuff. The 100% real stuff that make life, and chicken, great. With high quality farm raised chicken, we keep it real in everything we do. Keep it real. Keep it Tyson
{
"success": true,
"data": [
{
"id": 6,
"name": "Pureća prsa file",
"photo": "http://img.thefoodin.com/s4jpyvwm2c.png",
"unit": {
"id": 1,
"shortName": "Gra",