Skip to content

Instantly share code, notes, and snippets.

View afbelardi's full-sized avatar

Alex afbelardi

View GitHub Profile
@afbelardi
afbelardi / options.controller.spec.ts
Created March 19, 2023 23:47
Testing for NestJS controller using Jest
import { Test, TestingModule } from '@nestjs/testing';
import { OptionsController } from './options.controller';
import { OptionsService } from './options.service';
const mockOptions = {
_id: '62c78ca8cd673b254149b0c2',
backgroundColor: 'blue',
primaryColor: 'red',
secondaryColor: 'magenta',
@afbelardi
afbelardi / about.tsx
Created March 15, 2023 21:51
React Native Screen
// Filler text added for confidentiality
function AboutCompanyScreen({ themes, darkModeEnabled }: any) {
// Theme & Color Pallets
const colors = darkModeEnabled ? themes.dark : themes.light
const Paragraph = ({ children }: { children: any }) => (
<View
style={[
@afbelardi
afbelardi / resolvers.js
Last active March 15, 2023 20:31
Register and update users using GraphQL queries
export const resolvers = {
Query: {},
Mutation: {
loginUser: async (_, _args) => {
const username = _args.username;
const password = _args.password;
const version = "internal";
return axios
.post("https://xxxxxxxxxx.com/login", {
@afbelardi
afbelardi / handleSubmit.js
Created March 15, 2023 20:25
A submit function for a form to handle scenarios if correct information was input or not and display success or fail toast messages
const handleSubmit = async (e) => {
e.preventDefault();
try {
if (name.current.value === '' || email.current.value === '') {
setFieldIsEmpty(true);
} else {
const response = await fetch('https://nft-email.herokuapp.com/api/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
@afbelardi
afbelardi / pageViews.js
Created March 15, 2023 20:22
A function in a NestJS backend to increment page views for a user's profile
async addPageViews(id) {
const newDate = new Date(Date.now())
return await this.AnalyticsModel.findByIdAndUpdate(id, { $push: {"pageViews.datesViewed": newDate}, $inc: {"pageViews.timesViewed": 1}} ,{ new: true });
}
@afbelardi
afbelardi / linksClicked.js
Last active March 15, 2023 20:21
A function in a NestJS backend to determine how many time a link has been clicked for the purpose of analytics
async howManyClicks(analyticsId, id){
const foundAnalytics = await this.findAnalyticsById(analyticsId)
await this.AnalyticsModel.findByIdAndUpdate(analyticsId,
{ $inc: {totalLinkClicks: 1}},
{ new: true }
)
const foundLink = await foundAnalytics.linksClicked.filter((link) => {
return link.linkId === id;
});
if (foundLink.length > 0) {