Skip to content
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

Creator vitest #3109

Merged
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
2 changes: 1 addition & 1 deletion docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const config: Config = {
{
docs: {
sidebarPath: require.resolve("./sidebars.js"),
editUrl: ({ docPath }) => {
editUrl: ({ docPath }: { docPath: string }) => {
return `https://github.com/PalisadoesFoundation/talawa-api/edit/develop/docs/docs/${docPath}`;
},
},
Expand Down
204 changes: 204 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,195 @@ type FundCampaignsConnectionEdge {
node: FundCampaign
}

"""
Possible variants of the two-letter language code defined in ISO 639-1, part of the ISO 639 standard published by the International Organization for Standardization (ISO), to represent natural languages.
"""
enum Iso639Set1LanguageCode {
aa
ab
ae
af
ak
am
an
ar
as
av
ay
az
ba
be
bg
bi
bm
bn
bo
br
bs
ca
ce
ch
co
cr
cs
cu
cv
cy
da
de
dv
dz
ee
el
en
eo
es
et
eu
fa
ff
fi
fj
fo
fr
fy
ga
gd
gl
gn
gu
gv
ha
he
hi
ho
hr
ht
hu
hy
hz
ia
id
ie
ig
ii
ik
io
is
it
iu
ja
jv
ka
kg
ki
kj
kk
kl
km
kn
ko
kr
ks
ku
kv
kw
ky
la
lb
lg
li
ln
lo
lt
lu
lv
mg
mh
mi
mk
ml
mn
mr
ms
mt
my
na
nb
nd
ne
ng
nl
nn
no
nr
nv
ny
oc
oj
om
or
os
pa
pi
pl
ps
pt
qu
rm
rn
ro
ru
rw
sa
sc
sd
se
sg
si
sk
sl
sm
sn
so
sq
sr
ss
st
su
sv
sw
ta
te
tg
th
ti
tk
tl
tn
to
tr
ts
tt
tw
ty
ug
uk
ur
uz
ve
vi
vo
wa
wo
xh
yi
yo
za
zh
zu
}

"""
Possible variants of the two-letter country code defined in ISO 3166-1, part of the ISO 3166 standard published by the International Organization for Standardization (ISO), to represent countries, dependent territories, and special areas of geographical interest.
"""
Expand Down Expand Up @@ -1583,6 +1772,9 @@ input MutationCreateUserInput {
"""The sex assigned to the user at their birth."""
natalSex: UserNatalSex

"""Language code of the user's preferred natural language."""
naturalLanguageCode: Iso639Set1LanguageCode

"""Password of the user to sign in to the application."""
password: String!

Expand Down Expand Up @@ -1812,6 +2004,9 @@ input MutationSignUpInput {
"""The sex assigned to the user at their birth."""
natalSex: UserNatalSex

"""Language code of the user's preferred natural language."""
naturalLanguageCode: Iso639Set1LanguageCode

"""Password of the user to sign in to the application."""
password: String!

Expand Down Expand Up @@ -2029,6 +2224,9 @@ input MutationUpdateCurrentUserInput {
"""The sex assigned to the user at their birth."""
natalSex: UserNatalSex

"""Language code of the user's preferred natural language."""
naturalLanguageCode: Iso639Set1LanguageCode

"""Password of the user to sign in to the application."""
password: String

Expand Down Expand Up @@ -2249,6 +2447,9 @@ input MutationUpdateUserInput {
"""The sex assigned to the user at their birth."""
natalSex: UserNatalSex

"""Language code of the user's preferred natural language."""
naturalLanguageCode: Iso639Set1LanguageCode

"""Password of the user to sign in to the application."""
password: String

Expand Down Expand Up @@ -2976,6 +3177,9 @@ type User {
"""The sex assigned to the user at their birth."""
natalSex: UserNatalSex

"""Language code of the user's preferred natural language."""
naturalLanguageCode: Iso639Set1LanguageCode

"""
GraphQL connection to traverse through the organizations the user is a member of.
"""
Expand Down
98 changes: 98 additions & 0 deletions src/graphql/types/Advertisement/Advertisement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,110 @@ import {
AdvertisementAttachment,
type AdvertisementAttachment as AdvertisementAttachmentType,
} from "~/src/graphql/types/AdvertisementAttachment/AdvertisementAttachment";
import { TalawaGraphQLError } from "~/src/utilities/TalawaGraphQLError";

type User = {
id: string;
isAdmin: boolean;
};

type ContextType = {
currentClient: {
isAuthenticated: boolean;
user: User;
};
drizzleClient: {
query: {
usersTable: {
findFirst: (params: { where: { id: string } }) => Promise<User>;
};
};
};
log: {
error: (message: unknown) => void;
};
};

export type Advertisement = typeof advertisementsTable.$inferSelect & {
attachments: AdvertisementAttachmentType[] | null;
};

export const Advertisement = builder.objectRef<Advertisement>("Advertisement");
export const resolveCreator = async (
parent: Advertisement,
_args: Record<string, never>,
ctx: ContextType,
) => {
if (!ctx.currentClient.isAuthenticated) {
throw new TalawaGraphQLError({
message: "User is not authenticated",
extensions: {
code: "unauthenticated",
},
});
}

try {
// Add null check for creatorId before querying
if (!parent.creatorId) {
throw new TalawaGraphQLError({
message: "Associated creator not found for advertisement",
extensions: {
code: "arguments_associated_resources_not_found",
issues: [
{
argumentPath: ["creatorId"], // Use argumentPath instead of path
},
],
},
});
}

const user = await ctx.drizzleClient.query.usersTable.findFirst({
where: { id: parent.creatorId }, // Now guaranteed to be string
});

if (!user) {
ctx.log.error(`User with id ${parent.creatorId} not found`);
throw new TalawaGraphQLError({
message: "User not found",
extensions: {
code: "arguments_associated_resources_not_found",
issues: [
{
argumentPath: ["creatorId"], // Required by the type definition
},
],
},
});
}

if (
user.id !== ctx.currentClient.user.id &&
!ctx.currentClient.user.isAdmin
) {
throw new TalawaGraphQLError({
message: "User is not authorized",
extensions: {
code: "unauthorized_action",
},
});
}

return user;
} catch (error) {
if (error instanceof TalawaGraphQLError) {
throw error;
}
ctx.log.error(error);
throw new TalawaGraphQLError({
message: "Internal server error",
extensions: {
code: "unexpected",
},
});
}
NishantSinghhhhh marked this conversation as resolved.
Show resolved Hide resolved
};

Advertisement.implement({
description:
Expand Down
Loading
Loading