// the function that sets up the global context for each resolver, using the req const context = async ({ req }) => { // simple auth check on every request const auth = (req.headers && req.headers.authorization) || ''; const email = new Buffer(auth, 'base64').toString('ascii'); // if the email isn't formatted validly, return null for user if (!isEmail.validate(email)) return { user: null }; // find a user by their email const users = await store.users.findOrCreate({ where: { email } }); const user = users && users[0] ? users[0] : null; return { user: { ...user.dataValues } }; }
var insert_organization= function (req,res,next) { db.sync().then(function () { Organization.findOrCreate({where: {id: req.body.organization.id}, defaults: req.body.organization}) .spread((organization, created) => { console.log(created, organization); res.json(created); }); }).catch(function (error) { console.log(error); res.sendStatus(403) }) }
(async() => { const db = await getDB(); const users = db.users; await users.sync(); await users.findOrCreate({where: {name: 'user1'}}) await users.findOrCreate({where: {name: 'user2'}}) console.log('done!') })();
passport.use(new GoogleStrategy({ clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, callbackURL: "http://localhost:3000/api/auth/google/callback" }, (accessToken, refreshToken, profile, done) => { db.User.findOrCreate({ where: { googleId: profile.id, username: 'g_' + profile.name.givenName + '_' + profile.name.familyName, family_name: profile.name.familyName, given_name: profile.name.givenName, email: profile.emails[0].value }}) .spread((user, created) => { done(null, user) }) .catch((err) => { return done(new Error('Internal Server Error')) }) } ))
server.grant(oauth2orize.grant.code(function(client, redirectURI, user, ares, areq, done) { const code = uid(32) const valid_scopes = validateScope(areq.scope) db.AuthCode.create({ code: code, scope: JSON.stringify(valid_scopes), redirect_uri: redirectURI, clientId: client.id, userId: user.id, }) .then(() => { return db.UserClientGrant.findOrCreate({ where: { userId: user.id, clientId: client.id } }) .then(() => done(null, code)) }) .catch((err) => done('Internal Server Error')) }))
passport.use(new GitHubStrategy({ clientID: process.env.GITHUB_CLIENT_ID, clientSecret: process.env.GITHUB_CLIENT_SECRET, callbackURL: "http://localhost:3000/api/auth/github/callback" }, (accessToken, refreshToken, profile, done) => { db.User.findOrCreate({ where: { githubId: profile.id, username: profile.username, email: profile.emails[0].value }}) .spread((user, created) => { done(null, user) }) .catch((err) => { done(new Error('Internal Server Error')) }) } ));
Organization.findOrCreate({where: {id: 1}, defaults:_organization.organization }) .spread((organization, created) => { License.findOrCreate({where: {id: 1}, defaults:_license.license }) .spread((license, created) => { User.findOrCreate({where: {id: 1}, defaults:_user.user }) .spread((user, created) => {
var insert_contact= function (req,res,next) { db.sync().then(function () { Contact.findOrCreate({where: {id: req.body.contact.id}, defaults: req.body.contact}) .spread((contact, created) => { console.log(created, contact); res.json(created); }); }).catch(function (error) { console.log(error); res.sendStatus(403) }) }
var insert_job= function (req,res,next) { db.sync().then(function () { Job.findOrCreate({where: {id: req.body.job.id}, defaults: req.body.job}) .spread((job, created) => { console.log(created, job); res.json(created); }); }).catch(function (error) { console.log(error); res.sendStatus(403) }) }
var insert_note= function (req,res,next) { db.sync().then(function () { Note.findOrCreate({where: {id: req.body.note.id}, defaults: req.body.note}) .spread((note, created) => { console.log(created, note); res.json(created); }); }).catch(function (error) { console.log(error); res.sendStatus(403) }) }
var insert_candidate= function (req,res,next) { db.sync().then(function () { Candidate.findOrCreate({where: {id: req.body.candidate.id}, defaults: req.body.candidate}) .spread((candidate, created) => { console.log(created, candidate); res.json(created); }); }).catch(function (error) { console.log(error); res.sendStatus(403) }) }
var insert_company= function (req,res,next) { db.sync().then(function () { Company.findOrCreate({where: {id: req.body.company.id}, defaults: req.body.company}) .spread((company, created) => { console.log(created, company); res.json(created); }); }).catch(function (error) { console.log(error); res.sendStatus(403) }) }
var insert_license= function (req,res,next) { db.sync().then(function () { License.findOrCreate({where: {id: req.body.license.id}, defaults: req.body.license}) .spread((license, created) => { console.log(created, license); res.json(created); }); }).catch(function (error) { console.log(error); res.sendStatus(403) }) }
// the function that sets up the global context for each resolver, using the req const context = async ({ req }) => { // simple auth check on every request const auth = (req.headers && req.headers.authorization) || ''; const email = new Buffer(auth, 'base64').toString('ascii'); // if the email isn't formatted validly, return null for user if (!isEmail.validate(email)) return { user: null }; // find a user by their email const users = await store.users.findOrCreate({ where: { email } }); const user = users && users[0] ? users[0] : null; return { user: { ...user.dataValues } }; }