Skip to content

Commit

Permalink
api: Fix experiment schema
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Jan 18, 2023
1 parent 1881af0 commit 525f072
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/api/src/controllers/experiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ async function toUserId(emailOrId: string) {
return user.id;
}

const toUserIds = (emailsOrIds: string[]) =>
Promise.all(emailsOrIds.map(toUserId));
const toUserIds = (emailsOrIds?: string[]) =>
Promise.all(emailsOrIds?.map(toUserId) ?? []);

const app = Router();

Expand Down Expand Up @@ -129,7 +129,7 @@ app.patch("/:experiment", authorizer({ anyAdmin: true }), async (req, res) => {
!Array.isArray(audienceUserIds) ||
audienceUserIds.some((s) => typeof s !== "string")
) {
throw new BadRequestError("userIds must be an array of strings");
throw new BadRequestError("audienceUserIds must be an array of strings");
}

const experiment = await db.experiment.getByNameOrId(experimentQuery);
Expand All @@ -149,10 +149,10 @@ app.get("/:experiment", authorizer({ anyAdmin: true }), async (req, res) => {
experiment = {
...experiment,
audienceUsers: await Promise.all(
experiment.audienceUserIds.map(async (userId) => {
experiment.audienceUserIds?.map(async (userId) => {
const user = await db.user.get(userId);
return db.user.cleanWriteOnlyResponse(user);
})
}) ?? []
),
};

Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ components:
experiment-audience-payload:
type: object
additionalProperties: false
required: [type, stream]
properties:
addUsers:
type: array
Expand Down Expand Up @@ -2334,7 +2333,7 @@ components:
type: object
table: experiment
additionalProperties: false
required: [name, userIds]
required: [name]
properties:
type:
type: string
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/store/experiment-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { WithID } from "./types";

export async function isExperimentSubject(experiment: string, userId: string) {
const { audienceUserIds } = await db.experiment.getByNameOrId(experiment);
return audienceUserIds.includes(userId);
return audienceUserIds?.includes(userId) ?? false;
}

export async function ensureExperimentSubject(
Expand Down

0 comments on commit 525f072

Please sign in to comment.