chore: Move provisionSubdomain from Team model to teamCreator command
This commit is contained in:
@@ -21,44 +21,3 @@ describe("collectionIds", () => {
|
||||
expect(response[0]).toEqual(collection.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe("provisionSubdomain", () => {
|
||||
it("should set subdomain if available", async () => {
|
||||
const team = await buildTeam();
|
||||
const subdomain = await team.provisionSubdomain("testy");
|
||||
expect(subdomain).toEqual("testy");
|
||||
expect(team.subdomain).toEqual("testy");
|
||||
});
|
||||
|
||||
it("should set subdomain append if unavailable", async () => {
|
||||
await buildTeam({
|
||||
subdomain: "myteam",
|
||||
});
|
||||
const team = await buildTeam();
|
||||
const subdomain = await team.provisionSubdomain("myteam");
|
||||
expect(subdomain).toEqual("myteam1");
|
||||
expect(team.subdomain).toEqual("myteam1");
|
||||
});
|
||||
|
||||
it("should increment subdomain append if unavailable", async () => {
|
||||
await buildTeam({
|
||||
subdomain: "myteam",
|
||||
});
|
||||
await buildTeam({
|
||||
subdomain: "myteam1",
|
||||
});
|
||||
const team = await buildTeam();
|
||||
const subdomain = await team.provisionSubdomain("myteam");
|
||||
expect(subdomain).toEqual("myteam2");
|
||||
expect(team.subdomain).toEqual("myteam2");
|
||||
});
|
||||
|
||||
it("should do nothing if subdomain already set", async () => {
|
||||
const team = await buildTeam({
|
||||
subdomain: "example",
|
||||
});
|
||||
const subdomain = await team.provisionSubdomain("myteam");
|
||||
expect(subdomain).toEqual("example");
|
||||
expect(team.subdomain).toEqual("example");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -146,35 +146,6 @@ class Team extends ParanoidModel {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Move to command
|
||||
provisionSubdomain = async function (
|
||||
requestedSubdomain: string,
|
||||
options = {}
|
||||
) {
|
||||
if (this.subdomain) {
|
||||
return this.subdomain;
|
||||
}
|
||||
let subdomain = requestedSubdomain;
|
||||
let append = 0;
|
||||
|
||||
for (;;) {
|
||||
try {
|
||||
await this.update(
|
||||
{
|
||||
subdomain,
|
||||
},
|
||||
options
|
||||
);
|
||||
break;
|
||||
} catch (err) {
|
||||
// subdomain was invalid or already used, try again
|
||||
subdomain = `${requestedSubdomain}${++append}`;
|
||||
}
|
||||
}
|
||||
|
||||
return subdomain;
|
||||
};
|
||||
|
||||
provisionFirstCollection = async (userId: string) => {
|
||||
await this.sequelize!.transaction(async (transaction) => {
|
||||
const collection = await Collection.create(
|
||||
|
||||
Reference in New Issue
Block a user