Skip to content

Feature: Create a Subscribe to our Newsletter page #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions api/functions/graphql/nexus-typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export interface NexusGenObjects {
projects: NexusGenRootTypes['ProjectInTournament'][]; // [ProjectInTournament!]!
}
PostComment: { // root type
author: NexusGenRootTypes['User']; // User!
author?: NexusGenRootTypes['User'] | null; // User
body: string; // String!
created_at: NexusGenScalars['Date']; // Date!
id: number; // Int!
Expand Down Expand Up @@ -653,7 +653,7 @@ export interface NexusGenFieldTypes {
Bounty: { // field return type
applicants_count: number; // Int!
applications: NexusGenRootTypes['BountyApplication'][]; // [BountyApplication!]!
author: NexusGenRootTypes['User']; // User!
author: NexusGenRootTypes['User'] | null; // User
body: string; // String!
cover_image: string | null; // String
createdAt: NexusGenScalars['Date']; // Date!
Expand Down Expand Up @@ -756,6 +756,7 @@ export interface NexusGenFieldTypes {
linkNostrKey: NexusGenRootTypes['User'] | null; // User
registerInTournament: NexusGenRootTypes['User'] | null; // User
setUserNostrKeyAsPrimary: NexusGenRootTypes['User'] | null; // User
subscribeToNewsletter: boolean; // Boolean!
unlinkNostrKey: NexusGenRootTypes['User'] | null; // User
updateLastSeenNotificationTime: NexusGenRootTypes['User'] | null; // User
updateProfileDetails: NexusGenRootTypes['User'] | null; // User
Expand Down Expand Up @@ -784,7 +785,7 @@ export interface NexusGenFieldTypes {
projects: NexusGenRootTypes['ProjectInTournament'][]; // [ProjectInTournament!]!
}
PostComment: { // field return type
author: NexusGenRootTypes['User']; // User!
author: NexusGenRootTypes['User'] | null; // User
body: string; // String!
created_at: NexusGenScalars['Date']; // Date!
id: number; // Int!
Expand Down Expand Up @@ -878,7 +879,7 @@ export interface NexusGenFieldTypes {
usersByNostrKeys: NexusGenRootTypes['NostrKeyWithUser'][]; // [NostrKeyWithUser!]!
}
Question: { // field return type
author: NexusGenRootTypes['User']; // User!
author: NexusGenRootTypes['User'] | null; // User
body: string; // String!
createdAt: NexusGenScalars['Date']; // Date!
excerpt: string; // String!
Expand All @@ -892,7 +893,7 @@ export interface NexusGenFieldTypes {
votes_count: number; // Int!
}
Story: { // field return type
author: NexusGenRootTypes['User']; // User!
author: NexusGenRootTypes['User'] | null; // User
body: string; // String!
comments: NexusGenRootTypes['PostComment'][]; // [PostComment!]!
comments_count: number; // Int!
Expand Down Expand Up @@ -1269,6 +1270,7 @@ export interface NexusGenFieldTypeNames {
linkNostrKey: 'User'
registerInTournament: 'User'
setUserNostrKeyAsPrimary: 'User'
subscribeToNewsletter: 'Boolean'
unlinkNostrKey: 'User'
updateLastSeenNotificationTime: 'User'
updateProfileDetails: 'User'
Expand Down Expand Up @@ -1702,6 +1704,9 @@ export interface NexusGenArgTypes {
setUserNostrKeyAsPrimary: { // args
key?: string | null; // String
}
subscribeToNewsletter: { // args
email: string; // String!
}
unlinkNostrKey: { // args
key: string; // String!
}
Expand Down
9 changes: 5 additions & 4 deletions api/functions/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface BaseUser {
type Bounty implements PostBase {
applicants_count: Int!
applications: [BountyApplication!]!
author: User!
author: User
body: String!
cover_image: String
createdAt: Date!
Expand Down Expand Up @@ -257,6 +257,7 @@ type Mutation {
linkNostrKey(event: NostrEventInput): User
registerInTournament(data: RegisterInTournamentInput, tournament_id: Int!): User
setUserNostrKeyAsPrimary(key: String): User
subscribeToNewsletter(email: String!): Boolean!
unlinkNostrKey(key: String!): User
updateLastSeenNotificationTime(timestamp: String!): User
updateProfileDetails(data: ProfileDetailsInput): User
Expand Down Expand Up @@ -319,7 +320,7 @@ interface PostBase {
}

type PostComment {
author: User!
author: User
body: String!
created_at: Date!
id: Int!
Expand Down Expand Up @@ -451,7 +452,7 @@ type Query {
}

type Question implements PostBase {
author: User!
author: User
body: String!
createdAt: Date!
excerpt: String!
Expand Down Expand Up @@ -479,7 +480,7 @@ enum RoleLevelEnum {
}

type Story implements PostBase {
author: User!
author: User
body: String!
comments: [PostComment!]!
comments_count: Int!
Expand Down
8 changes: 4 additions & 4 deletions api/functions/graphql/types/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const Story = objectType({
return post._count.comments;
},
});
t.nonNull.field("author", {
t.field("author", {
type: "User",
resolve: (parent) => {
return (
Expand Down Expand Up @@ -251,7 +251,7 @@ const Bounty = objectType({
t.nonNull.list.nonNull.field("applications", {
type: "BountyApplication",
});
t.nonNull.field("author", {
t.field("author", {
type: "User",
resolve: (parent) => {
return prisma.bounty.findUnique({ where: { id: parent.id } }).user();
Expand Down Expand Up @@ -287,7 +287,7 @@ const Question = objectType({
// }
// });

t.nonNull.field("author", {
t.field("author", {
type: "User",
resolve: (parent) => {
return prisma.question.findUnique({ where: { id: parent.id } }).user();
Expand All @@ -302,7 +302,7 @@ const PostComment = objectType({
t.nonNull.int("id");
t.nonNull.date("created_at");
t.nonNull.string("body");
t.nonNull.field("author", {
t.field("author", {
type: "User",
});
t.int("parentId");
Expand Down
28 changes: 28 additions & 0 deletions api/functions/graphql/types/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const {
validateEvent,
} = require("../../../utils/nostr-tools");
const { queueService } = require("../../../services/queue-service");
const { error } = require("console");

const BaseUser = interfaceType({
name: "BaseUser",
Expand Down Expand Up @@ -767,6 +768,32 @@ const updateLastSeenNotificationTime = extendType({
},
});

const subscribeToNewsletter = extendType({
type: "Mutation",
definition(t) {
t.nonNull.boolean("subscribeToNewsletter", {
args: { email: nonNull(stringArg()) },
async resolve(_root, { email }, ctx) {
const user = await getUserById(ctx.user?.id);

// TODO: store in the DB that the user is subscribed to the newsletter
await queueService.emailService
.subscribeToNewsletter({
email,
user_id: user?.id,
user_name: user?.name,
})
.catch((err) => {
console.log(err);
throw err;
});

return true;
},
});
},
});

const WalletKey = objectType({
name: "WalletKey",
definition(t) {
Expand Down Expand Up @@ -1003,4 +1030,5 @@ module.exports = {
unlinkNostrKey,
setUserNostrKeyAsPrimary,
updateLastSeenNotificationTime,
subscribeToNewsletter,
};
8 changes: 8 additions & 0 deletions api/services/queue-service/emails-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const emailService = {
track_id,
});
},

subscribeToNewsletter: ({ email, user_id, user_name }) => {
return callQueueApi("/add-job/emails/subscribe-to-newsletter", {
email,
user_id,
user_name,
});
},
};

module.exports = emailService;
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
-- DropForeignKey
ALTER TABLE "FoundersClubMember" DROP CONSTRAINT "FoundersClubMember_user_id_fkey";

-- DropForeignKey
ALTER TABLE "NostrBadgeRequest" DROP CONSTRAINT "NostrBadgeRequest_userId_fkey";

-- DropForeignKey
ALTER TABLE "ProjectMember" DROP CONSTRAINT "ProjectMember_userId_fkey";

-- DropForeignKey
ALTER TABLE "TournamentJudgingRoundJudge" DROP CONSTRAINT "TournamentJudgingRoundJudge_judge_id_fkey";

-- DropForeignKey
ALTER TABLE "TournamentJudgingRoundJudgeScore" DROP CONSTRAINT "TournamentJudgingRoundJudgeScore_judge_id_fkey";

-- DropForeignKey
ALTER TABLE "TournamentOrganizer" DROP CONSTRAINT "TournamentOrganizer_user_id_fkey";

-- DropForeignKey
ALTER TABLE "TournamentParticipant" DROP CONSTRAINT "TournamentParticipant_user_id_fkey";

-- DropForeignKey
ALTER TABLE "UserAction" DROP CONSTRAINT "UserAction_user_id_fkey";

-- DropForeignKey
ALTER TABLE "UserBadge" DROP CONSTRAINT "UserBadge_userId_fkey";

-- DropForeignKey
ALTER TABLE "UserBadgeProgress" DROP CONSTRAINT "UserBadgeProgress_userId_fkey";

-- DropForeignKey
ALTER TABLE "UserEmail" DROP CONSTRAINT "UserEmail_user_id_fkey";

-- DropForeignKey
ALTER TABLE "UserKey" DROP CONSTRAINT "UserKey_user_id_fkey";

-- DropForeignKey
ALTER TABLE "UserNostrKey" DROP CONSTRAINT "UserNostrKey_user_id_fkey";

-- DropForeignKey
ALTER TABLE "UsersOnWorkRoles" DROP CONSTRAINT "UsersOnWorkRoles_userId_fkey";

-- AddForeignKey
ALTER TABLE "UserKey" ADD CONSTRAINT "UserKey_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserNostrKey" ADD CONSTRAINT "UserNostrKey_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserEmail" ADD CONSTRAINT "UserEmail_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UsersOnWorkRoles" ADD CONSTRAINT "UsersOnWorkRoles_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ProjectMember" ADD CONSTRAINT "ProjectMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TournamentParticipant" ADD CONSTRAINT "TournamentParticipant_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "FoundersClubMember" ADD CONSTRAINT "FoundersClubMember_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserAction" ADD CONSTRAINT "UserAction_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserBadgeProgress" ADD CONSTRAINT "UserBadgeProgress_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserBadge" ADD CONSTRAINT "UserBadge_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "NostrBadgeRequest" ADD CONSTRAINT "NostrBadgeRequest_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TournamentJudgingRoundJudge" ADD CONSTRAINT "TournamentJudgingRoundJudge_judge_id_fkey" FOREIGN KEY ("judge_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TournamentJudgingRoundJudgeScore" ADD CONSTRAINT "TournamentJudgingRoundJudgeScore_judge_id_fkey" FOREIGN KEY ("judge_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TournamentOrganizer" ADD CONSTRAINT "TournamentOrganizer_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Loading